Custom Search

Changing the sign of a binary number

Suppose we have the eight bit number for 42 in binary and have to determine the eight bit form for -42.

MSB

sign

bit

            LSB Number

27

26 25 24 23 22 21 20  
  64 32 16 8 4 2 1  
0 0 1 0 1 0 1 0 0010 1010
    32   +8   +2   = 42 (decimal)
1 1 0 1 0 1 1 0 1101 0110
-128 +64   +16   +4 +2   =-42 (decimal)

Start with the positive binary value:

0010 1010

move from the LSB end of the number to the first '1'

0010 1010

that '1' and and zeros after it stay the same as they are!

You now move up to the MSB inverting numbers as you go:

 

1101 0110

It is also possible to find out the value of a negative number that starts off with lots of 1s in a quick way! We simply convert the negative number to a positive by reversing the steps above.

For example: What is the decimal value of the binary number 1111 1111 0010 ?

Okay, the first step is to chang the 1s to zeros and vice versa - starting at the MSB and going to the 1 that is nearest to the LSB.

That means all of the figures in green have to 'flip' and the red 1 (and those beyond the 1 in red) stay the same.

1111 1111 0010

We therefore get : 0000 0000 1110 - this is the positive version of the number we have to determine in decimal.

In decimal this is 8 + 4 + 2 = 14 we therefore know that the number we were given is equal to -14 in decimal.

To check our answer we can do the math... but you have got to admit my method is quicker! (especially if you haven't a calculator).

MSB

sign

bit

 

LSB
Number
211
210
29
28

27

26
25
24
23
22
21
20
2048
1024
512
256
128
64
32
16
8
4
2
1
1
1
1
1
1
1
1
1
0
0
1
0
111111110010
-2048
+1024
+512
+256
+128
+64
+32
+16
+2
= -14