In java, to get a sequence of 1s and 0s in the form of a binary number, you can do the following
(-1 << (4))
while will give me the result
11110000
Since python does not support signed ints, what is the equivalent way of doing this in python? Ideally, I would prefer to do this without any external library.
Try :
>>> bin(0xf << 4)[2:]
'11110000'
>>>
Or,
>>> print ('{0:b}'.format(0xf << 4))
11110000
>>> '{0:b}'.format(0xf << 4)
'11110000'
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With