Difference between revisions of "W1032 Negative Integers"
From Coder Merlin
Line 10: | Line 10: | ||
Initially this may appear to be a good solution, but let's explore further. | Initially this may appear to be a good solution, but let's explore further. | ||
{{Observe| | |||
Section 1: Reserved Bit Encoding | |||
# How would <math>\color{White}+11_{10}</math> be encoded? | |||
# How would <math>\color{White}-11_{10}</math> be encoded? | |||
# How would you add these two numbers (<math>\color{White}+11_{10} + -11_{10}</math>) 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 == | == References == | ||
* [https://en.wikipedia.org/wiki/Method_of_complements Complements] (Wikipedia) | * [https://en.wikipedia.org/wiki/Method_of_complements Complements] (Wikipedia) |
Revision as of 14:55, 21 June 2019
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)