Binary Number Data Type

Signed vs. Unsigned Numbers

Was also learning more about this at Ericsson.

  • In a signed representation, the largest number is . The next number after is (the largest negative number)
    • I.e. go from (largest positive number) to (largest negative number)
  • In an unsigned representation, the largest number is . The next number after is .
    • i.e. go from to

Don’t believe me? The Source of Truth is code right. Consider the following code:

int x = 1 << 31 - 1; // LARGEST signed number
cout << x << "\n"; // 2147483647 
x++; 
cout << x << "\n"; // -2147483648
 
unsigned int x = (1 << 32) - 1; // Might give a warning, this is the largest unsigned number
cout << x << "\n"; // 4294967295 
x++; 
cout << x << "\n"; // 0

Notice that unsigned can give a bigger number because you have that additional bit that would otherwise be used to represent the negative sign for the signed numbers.

To understand how to read /write these signed numbers, see Complement.