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:

Positive 5

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:

Negative 5, Reserved Bit

Initially this may appear to be a good solution, but let's explore further.

References[edit]