Create an integer variable by assigning binary value in Python

Program

a = 0b1010
b = 0b00000000
c = 0b11111111
d = 0b11110000
e = 0b10101010

# printing types
print("type of the variables...")
print("type of a: ", type(a))
print("type of b: ", type(b))
print("type of c: ", type(c))
print("type of d: ", type(d))
print("type of e: ", type(e))

# printing values in decimal format
print("value of the variables in decimal format...")
print("value of a: ", a)
print("value of b: ", b)
print("value of c: ", c)
print("value of d: ", d)
print("value of e: ", e)

# printing values in binary format
print("value of the variables in binary format...")
print("value of a: ", bin(a))
print("value of b: ", bin(b))
print("value of c: ", bin(c))
print("value of d: ", bin(d))
print("value of e: ", bin(e))

Output

Create an integer variable by assigning binary value in Python

Leave a Comment

error: Alert: Content is protected!!