Cryptography Reference
In-Depth Information
1000
8
1001
7
1010
6
1011
5
110 0
4
1101
3
1110
2
1111
1
If you subtract 3 (0011) from 1 (0001), the counters naturally wrap and end up
back on 1110, which is chosen to represent 2. Multiplication preserves sign as
well - 2
3
0010
1101:
1101
0010
0000 (0)
11010 (1)
000000 (0)
0000000 (0)
0011010
Truncate the leading three digits and you get the correct result: 1010, or 6.
This truncation creates a problem when you're trying to implement arbitrary
precision binary math, though. Consider 7
7, which overfl ows this four-bit
implementation:
0111
0111
0111 (1)
01110 (1)
011100 (1)
0000000 (0)
11001
You've computed the correct answer — 49 — but according to the rule stated
earlier, you should throw away the fi rst bit and end up with an incorrect answer
of 7. You could, of course, check the magnitude of each operand, check to see
if it would have overfl owed, and adjust accordingly, but this is an awful lot of
Search WWH ::




Custom Search