|
|
|
|
|
by o11c
760 days ago
|
|
Or briefly, copied from my StackOverflow answer[1]: v 000...00010100
~v 111...11101011 (not used directly, all bits opposite)
-v 111...11101100 (-v == ~v + 1; this causes all low 1 bits to overflow and carry)
v&-v 000...00000100 (has a single 1 bit, from the carry)
The linked article is wrong in only mentioning 2 signed integer representations. Old versions of C allowed 3 representations for integers, floats use one of those (sign-magnitude, also used widedly by bignum libraries) and one other (offset binary), and base negative-2 is also possible in theory (not sure if practical for anything), for a total of 5.[1]: https://stackoverflow.com/a/63552117/1405588 |
|
TIL we have 5 such representations! :)