Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Negative Binary Numbers & Binary Subtraction 2’s Complement 2’s Complement is a way to represent negative numbers in binary. Recall the Odometer analogy: On a car odometer, all the digits eventually reset to 0s. The same applies to a “binary odometer”. What would a binary odometer look like as it approaches and passes the “reset” point? (Reset) 1101 Represents -3 1110 Represents -2 1111 Represents -1 0000 0001 Represents 1 0010 Represents 2 0011 Represents 3 2’s Complement Cont’d In Computers, the memory is divided up into bytes – or groups of 8 bits. 1111 1101 In byte format: 1111 1110 1111 1111 (Reset) 0000 0000 0000 0001 0000 0010 0000 0011 In all negative binary numbers, the left-most bit is always 1. This bit is called the “sign bit”. That is, if the sign bit (left bit in a group of 8) is 1, the number is negative. Fortunately, there is an easy way of finding the negatives of binary numbers – it is called the 2’s Complement Method. Finding the 2’s Complement There are 2 steps: 1) Flip all the bits (all 1’s become 0, & 0’s become 1) 2) Add 1 to the new number. Example: Find the negative (aka 2’s Complement) of 0010 1101 (decimal number 45) Step 1: Flip the bits. Step 2: Add 1. Sign Bit 00101101 11010010 + 1 11010011 (Answer: Proof: 128-64-0-16-0-0-2-1 = 45 -45) Binary Subtraction Use the following steps: 1) Find the 2’s Complement of the number being subtracted. 2) Add the new number to the number it is being subtracted from. 3) Discard the overflow bit. Example: Find 01110111 – 00010111 (119 – 23) 1) 2’s Complement of 00010111: 11101000 + 1 11101001 (Flip the Bits) (Add 1) Binary Subtraction Cont’d 2) Add the Original Number and the 2’s Complement Number: Overflow Bit 01110111 +11101001 1 01100000 Original Number 2’s Complement Number 3) Discard the Overflow Bit: 01100000 (Decimal 96) (119 – 23 = 96) (Proof: 0 + 64 + 32 + 0 + 0 + 0 + 0 + 0 = 96)