Common number bases

From CS2800 wiki

Decimal

The most common number base is base 10, or decimal. This is how we usually interpret numbers. It is convenient because most people have ten fingers and that's how we first learn to count.

No special notation is needed to indicate decimal, since that's how we normally interpret numbers. For example, [math]1234 [/math] means [math]\href{/cs2800/wiki/index.php/Base}{(1234)_{10}} [/math].

Binary

In digital logic, it is convenient to represent numbers using high and low voltages; We can think of a high voltage as "1" and a low voltage as "0"; allowing us two digits to work with. Thus it is convenient to represent numbers in base 2, which is also called binary.

Binary digits are also called bits.

Binary numbers are sometimes written with a leading "b", as in "b1101", which is another way of writing [math](1101)_2 [/math] or [math]13 [/math].

Hexadecimal

Hexadecimal is another word for base 16. It is useful for a few reasons:

  • In decimal, dividing by 10 and taking the remainder are very easy operations: the quotient is represented by all the digits but the last, while the remainder is represented by the last. Dividing by 100 and other powers of 10 is similarly easy. In some applications, it is useful to be able to easily divide by 16 (or other high powers of 2), and this is easier to do by humans if the numbers are written down in base 16.
  • A single hexadecimal digit is a number that can be represented by 4 bits, so it is easier to translate between hexadecimal and binary than it is between other number bases.


In order to represent numbers in hexadecimal, we need digits to represent the numbers between ten and fifteen. People usually use the letters a–f for this purpose, with a standing for 10, b for 11, etc.

Hexadecimal numbers are often prefixed with a "0x". For example, [math]0x2c [/math] is another way of writing [math](2c)_{16} [/math], which is another way of writing [math]44 [/math].

Octal

Octal is another word for base 8. It is useful for the same reasons as hexadecimal notation, although it is less commonly used. Some programming languages allow you to write a number in octal notation by prefixing it with a 0 as in "0172" which (in some contexts) would be interpreted as [math]\href{/cs2800/wiki/index.php/Base}{(0172)}_8 [/math] or [math]122 [/math].

Ascii and Unicode

Computers are good at processing numbers, but a lot of what we process are strings of characters. By numbering each possible character, we can use Base b interpretation and Base b representation to convert from strings of characters to natural numbers and back.

ASCII and Unicode are two ways to assign a digit to each character. ASCII stands for the "American standard code for information interchange"; it is just a table mapping 128 characters (e.g. 'A', 'B', 'a', 'b', '!', '0', ')', etc) to the base 128 digits.

Unicode is the same idea, except that there are 1,114,112 unicode characters in the table (including things like '∧', '∃', '喂', '😀', '🐱', and '💩'). You can think of unicode as a way to write down numbers in base 1,114,112.

Because base b representation is a bijection (since every number has a base b representation and the base b representation is unique), we will simply treat strings as numbers and vice-versa without paying much more attention to it.