bit_manipulation.binary_twos_complement

Functions

twos_complement(→ str)

Take in a negative integer 'number'.

Module Contents

bit_manipulation.binary_twos_complement.twos_complement(number: int) str

Take in a negative integer ‘number’. Return the two’s complement representation of ‘number’.

>>> twos_complement(0)
'0b0'
>>> twos_complement(-1)
'0b11'
>>> twos_complement(-5)
'0b1011'
>>> twos_complement(-17)
'0b101111'
>>> twos_complement(-207)
'0b100110001'
>>> twos_complement(1)
Traceback (most recent call last):
    ...
ValueError: input must be a negative integer