W1032 Negative Integers
From Coder Merlin
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Prerequisites[edit]
Background[edit]
What methods might we use to encode negative integers? As a first approach, perhaps we can use one of the bits of our word to represent the sign. Let's consider a single-byte word and the number . This may be encoded as:
If we were to reserve the most-significant bit, bit seven, to indicate whether our number was positive or negative, we can use the remaining seven bits to store the absolute value of the number. In such a case, the number would be encoded as:
Initially this may appear to be a good solution, but let's explore further.
Observe
Observe, Ponder, and Journal:
Section 1: Reserved Bit Encoding
- How would be encoded?
- How would be encoded?
- How would you add these two numbers () in binary?
- How many alternative representations are there for the number 0?
- Given the above, do you think that this method of encoding is ideal? Why or why not?
References[edit]
- Complements (Wikipedia)