python - Force integers of a given size with bin? -
i'm playing around bitwise operators more comfortable using them.
the problem i'm having since python has infinite width integers, it's difficult see actual results of operations.
>>> bin(0b00000001 & 0b11110111) 0b1 i'd see 0b00000001 instead.
is there way experiment these operators fixed-size integers in python?
use format() function:
print(format(0b00000001 & 0b11110111, '#010b')) output
0b00000001 the string parameter format() function specifies format of output. # makes output include 0b prefix, , 10 indicates entire output should 10 characters. 0 preceding 10 enforces 0 left-padding in 10 output characters. can remove hash if want remove 0b prefix.
Comments
Post a Comment