bit_manipulation.binary_or_operator¶
Bitwise OR helper.
Return a zero-padded binary string representing a | b where the width is the
maximum bit length of the inputs. Only non-negative integers are accepted.
>>> binary_or(25, 32)
'0b111001'
>>> binary_or(37, 50)
'0b110111'
>>> binary_or(21, 30)
'0b11111'
>>> binary_or(58, 73)
'0b1111011'
>>> binary_or(0, 255)
'0b11111111'
>>> binary_or(0, 256)
'0b100000000'
Invalid inputs raise clear exceptions:
>>> binary_or(0, -1)
Traceback (most recent call last):
...
ValueError: inputs must be non-negative integers
>>> binary_or(0, 1.1)
Traceback (most recent call last):
...
TypeError: inputs must be integers
>>> binary_or("0", "1")
Traceback (most recent call last):
...
TypeError: inputs must be integers
Functions¶
|
Module Contents¶
- bit_manipulation.binary_or_operator.binary_or(a: int, b: int) str¶