Signed and Unsigned Integers

Learn about signed and unsigned integers.

Signed and unsigned integers

Previously, we discussed the different set of integer types a language has. If we think about how negative numbers can be represented, we’ll see that we have a problem. When working with binary numbers, we have several bits that can store either 0 or 1, but we don’t have any other values, so we can’t just insert a minus sign to indicate that this is a negative number. Instead, one of three methods can be used. Let’s see how they work.

Sign-magnitude representation (SMR)

Even if the name is a bit complicated, sign-magnitude representation is the easiest way to represent negative values in the binary format. Imagine that we’re working with one byte that gives us eight bits to represent a value. However, if we assign one of the bits to represent whether this is a positive or negative value, we’re left with just seven bits for the actual value:

Get hands-on with 1200+ tech skills courses.