Wednesday, 9 November 2016

2' Complement Binary


Representing negative integers


Negative numbers can also be represented in binary. The name of the system most commonly used to represent and handle negative numbers is '2s Complement'. There are two common methods used to figure out how a negative number is stored using 2s complement.
2's Complement

The first technique involves three steps:

Find the positive value

Switch 1s and 0s
Add 1



To represent -116, the following steps would be followed:

1. Find positive 116
128  64   32   16   8   4   2   1
   0    1     1     1    0   1   0   0




2. Switch 1s and 0s
128   64   32   16   8   4   2   1
 0       1     1     1    0   1   0   0
 1       0     0     0    1   0   1   1




3. Add 1

To add one, it is necessary to start at the right hand side of the number. If the number on the right is a 1, move to the next number. Keep moving from right to left until you find a 0.

In this example there is a 0 underneath the number 4. This 0 would become a 1. The 1s that are to the right of the 0 that was found first need to change from being a 1 to a 0:

128   64   32   16   8   4   2   1
  1      0     0     0    1   0   1   1
  1      0     0     0    1   1   0   0




10001100 = -116

No comments:

Post a Comment