Python bin()

The bin() function converts an integer , both positive and negative, into binary form.

Syntax

bin(n)

n – integer being converted

Example

w = 25
x = -10
y = bin(w)[2:] #remove prefix 0b

print(bin(w))
print(bin(x))
print(y)

Output

0b11001
-0b1010
11001

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s