Two’s Complement

is
0   = 0000 0000
8 = 0000 1000
16 = 0000 1111
127 = 0111 1111
0000 1000. 
Then we flip all the bits
0000 1000 becomes 1111 0111
then we add 1 to it
1111 0111 becomes 1111 1000.
0    = 0000 0000
8 = 0000 1000
-8 = 1111 1000
16 = 1111 0001
127 = 0111 1111
-127 = 1000 0001
1111 1000
Then we flip the bits so
1111 1000 becomes 0000 0111
then we add 1 so
0000 0111 becomes 0000 1000
1000 0000
Then we flip the bits so
1000 0000 becomes 0111 1111
then we add 1 so
0111 1111 becomes 1000 0000

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store