Signed Integer

A signed integer is a data type in computer science and mathematics that can represent both positive and negative whole numbers by assigning or to the leftmost bit to indicate the sign of the integer. Signed integers can therefore represent numbers between and inclusive, where represents the number of bits representing the integer.

Intuition

Let’s start with formulating the range of signed integers. We previously said that unsigned integers can represent numbers in the range . However, when using signed integers, two issues arise:

  1. There is a -0 and +0! We can see this with a quick example: as the leftmost bit is allocated to the number sign, 0b1000 and 0b0000 are the same number!
  2. Similarly, because the leftmost bit takes up space, we can only utilize bits for our signed integer.
    Combining the two facts, we get our desired range: .

We also arise into something else here: adding a positive and a negative number always leads to a negative number!