Sunday, May 19, 2013

Binary Substraction

Binary subtraction
When it comes to subtracting one number from another in binary things can get very messy.
X (82 denary) 0101 0010
Y (78 denary) 0100 1110 −
An easier way to subtract Y from X is to add the negative value of Y to the value of X
X−Y = X+(−Y)
To do this we first need to find the negative value of Y (82 denary)
0100 1110 find the right most one

0100 1110 
1011 0010 flip all the bits to its left
Now try the sum again
   0101 0010     X( 82 denary) 
   1011 0010 +   Y(−78 denary)
   0000 0100
(¹)¹¹¹   ¹       the one carried over the bit 9 is ignored
Which comes out as
128  64  32  16   8   4   2   1 
  0   0   0   0   0   1   0   0
                      4         = 4 = 82-78
Exercise: Binary subtraction
Find the answers to the following sums in binary, show your working
  0110 1100 (108)
- 0000 0111 (7)

Answer :
Convert the 0000 0111 into a negative number 1111 1001 = -7 Add both numbers together:
   0110 1100
 + 1111 1001
   0110 0101 = 101
(¹)¹¹¹¹         the one carried over the bit 9 is ignored
  0001 1111 (31)
- 0001 0011 (19)
  
Answer :
Convert the 0001 0011 into a negative number 1110 1101 = -19 Add both numbers together:
   0001 1111
 + 1110 1101
   0000 1100 = 12
(¹)¹¹¹¹ ¹¹¹    the one carried over the bit 9 is ignored
  0111 0111 (119)
- 0101 1011 (91)
  
Answer :
Convert the 0101 1011 into a negative number 1010 0101 = -91 Add both numbers together:
   0111 0111
 + 1010 0101
   0001 1100 = 28
(¹)¹¹   ¹¹¹    the one carried over the bit 9 is ignored
23 (hex)  - 1F (hex)

Answer :
Convert the HEX values to binary
0010 0011 = 23 HEX or 35 denary
0001 1111 = 1F HEX or 31 denary
Now let's find the negative value of 1F
1110 0001 = -31
Add both numbers together:
   0010 0011
 + 1110 0001
   0000 0100 = 4
(¹)¹¹¹   ¹¹    the one carried over the bit 9 is ignored
  0001 0010 (10)
- 1111 1101 (-31)
  
Answer :
They have tried to trick you. What is the a number minus a negative number? X - (-Y) = X + Y
Let's start by finding the value of the bottom number: 1110 0001 -> 0001 1111 = -31
And by working this out we have the positive value (0001 1111) Add both numbers together:
   0001 0010 (18)
 + 0001 1111 (31)
   0011 0001 = 49
(¹)  ¹

No comments:

Post a Comment