Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix example of ones' complement sum #83

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

lvgrr
Copy link
Contributor

@lvgrr lvgrr commented Oct 12, 2024

book/direct/error.rst

Lines 108 to 118 in dd26bf8

In ones’ complement arithmetic, a negative integer (-x) is represented
as the complement of x; that is, each bit of x is inverted. When adding
numbers in ones’ complement arithmetic, a carryout from the most
significant bit needs to be added to the result. Consider, for example,
the addition of -5 and -3 in ones’ complement arithmetic on 4-bit
integers: +5 is 0101, so -5 is 1010; +3 is 0011, so -3 is 1100. If we
add 1010 and 1100, ignoring the carry, we get 0110. In ones’ complement
arithmetic, the fact that this operation caused a carry from the most
significant bit causes us to increment the result, giving 0111, which is
the ones’ complement representation of -8 (obtained by inverting the
bits in 1000), as we would expect.

The example of ones' complement sum above is wrong because -8 cannot be represented in ones' complement arithmetic on 4-bit integers. 0111 is the representation of 7, not -8.

I propose changing the example to the sum -5 and -2.

@CLAassistant
Copy link

CLAassistant commented Oct 12, 2024

CLA assistant check
All committers have signed the CLA.

@drbruced12
Copy link
Contributor

Agreed, the text as written is either confusing or wrong; this is a helpful fix.

@drbruced12 drbruced12 merged commit 01802de into SystemsApproach:master Oct 16, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants