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
No comments:
Post a Comment