c++ - Why "-1" is 11111111 not 10000001 in signed int -


this question has answer here:

i'm doubt why uses -1 11111111 in signed int, not 10000001. because learned first bit use specify sign , rest of 7 bits value. in reason designers decide use -1

[ first bit = 1 , value 7 bits=127 ] not [ first bit = 1 , value 7 bits=1 ]

c , c++ allow both sign-and-magnitude (with -1 10000001) , two's complement form (with -1 11111111).

in addition both languages allow one's complement form (with -1 11111110).

however, on extant platforms two's complement form used. 1 main advantage (the “why” ask about) values same wrap-around unsigned arithmetic, unsigned in c , c++. put way, if interpret same bits unsigned value, differs negative value 2n, n number of value representation bits.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -