I'm translating this from C to Python:
int_fast16_t x;
int_fast16_t y = compute_value();
x = ~y;
y = x+1;
I don't think
y = compute_value()
y = (~y) + 1
will work: how would it know on how many bits should the binary NOT be done? (8? 16? 32?).
In the case of C, it is explicit with the type int_fast16_t
, but with Python we don't know a number of bits in advance.
How do you do this in Python?
I have read How do I do a bitwise Not operation in Python? but here it's more specific: how does Python infer the number of bits to use in a binary NOT?
Example:
How does Python know if the binary NOT of 3
(0b11
) should be done on 4 bits: 0b00
or on 8 bits: 0b11111100
or on 16 bits: 0b1111111111111100
?