3 ms·
Looks like count_bits loops infinitely if given a negative number. The wiki (https://wiki.python.org/moin/BitwiseOperators https://wiki.python.org/moin/Bitwise
by asteroidfodder 10y ago
Looks like count_bits loops infinitely if given a negative number.
The wiki (https://wiki.python.org/moin/BitwiseOperators https://wiki.python.org/moin/BitwiseOperators) says:
Of course, Python doesn't use 8-bit numbers. It USED to use however many bits were native to your machine, but since that was non-portable, it has recently switched to using an INFINITE number of bits. Thus the number -5 is treated by bitwise operators as if it were written "...1111111111111111111011".