Skip to content

Commit 01802de

Browse files
authored
Merge pull request #83 from lvgrr/master
Fix example of ones' complement sum
2 parents dd26bf8 + 5653737 commit 01802de

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

direct/error.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ In ones’ complement arithmetic, a negative integer (-x) is represented
109109
as the complement of x; that is, each bit of x is inverted. When adding
110110
numbers in ones’ complement arithmetic, a carryout from the most
111111
significant bit needs to be added to the result. Consider, for example,
112-
the addition of -5 and -3 in ones’ complement arithmetic on 4-bit
113-
integers: +5 is 0101, so -5 is 1010; +3 is 0011, so -3 is 1100. If we
114-
add 1010 and 1100, ignoring the carry, we get 0110. In ones’ complement
112+
the addition of -5 and -2 in ones’ complement arithmetic on 4-bit
113+
integers: +5 is 0101, so -5 is 1010; +2 is 0010, so -2 is 1101. If we
114+
add 1010 and 1101, ignoring the carry, we get 0111. In ones’ complement
115115
arithmetic, the fact that this operation caused a carry from the most
116-
significant bit causes us to increment the result, giving 0111, which is
117-
the ones’ complement representation of -8 (obtained by inverting the
118-
bits in 1000), as we would expect.
116+
significant bit causes us to increment the result, giving 1000, which is
117+
the ones’ complement representation of -7 (obtained by inverting the
118+
bits in 0111), as we would expect.
119119

120120
The following routine gives a straightforward implementation of the
121121
Internet’s checksum algorithm. The ``count`` argument gives the length

0 commit comments

Comments
 (0)