Changing the sign of a binary numberSuppose we have the eight bit number for 42 in binary and have to determine the eight bit form for -42.
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).
|
|