# Numeral systems

## What is a number system?

What is a number system? The phrase "number system" has multiple meanings. One meaning of a number system is a system of representing numbers of a certain type. For example the decimal system, which we use regurarly.

The decimal system has a "base" or "radix" of 10. It means that is has 10 unique digits or symbols (for example letters) that can represent an arbitrary number or value. For example, the decimal system, or the base 10 system, has the digits (or "symbols") 0 through 9.

Ten different digits. 0 is the first digit. If we increase 0 by one we get 1, increase it again, we get 2, and so on. 8 increased by one is 9. But what comes after 9? We have used up all the ten digits in the decimal system. Well, we just add more digits! So in the decimal system, what comes after the tenth (and last) digit, 9? 10 of course, you would say! But why 10? Well, 9 can also be written as 09, and when we add one, the 9 resets back to a 0, and the 0 in 09 increases by 1, and we get 10!

This explanation probably isn't as good as it could be, but hopefully you understood it, and it is important to understand number systems, like binary, or octal.

Send any corrections and suggestions to [email protected]

## The binary system

The number system that computers use is calle biinary, and has a base of 2. That means that a numeric value can only be represented by two symbols. 1 and 0. To show it's a binary number we add a "b" at the end of the number. For example 1011b.

If we increase 0b, we get 1b. If we increase it again, we should get 2. But the symbol "2" does not exist in the binary system! So we have to represent it with the two symbols we have, 1 and 0. The number 2 in binary is 10. Why? Because 1 in binary is 1b, or rather 01b, and when it is increased by 1, the 0 in 01b becomes a 1, and the 1 in 01b resets back to 0.

Below is a list of the numbers 0 to 10 in binary. See if you can spot the pattern!

• 00 = 0000b
• 01 = 0001b
• 02 = 0010b
• 03 = 0011b
• 04 = 0100b
• 05 = 0101b
• 06 = 0110b
• 07 = 0111b
• 08 = 1000b
• 09 = 1001b
• 10 = 1010b

## Convert binary to decimal

To convert binary to decimal we need to know the "weights" of each digit. Take the binary number 1101b. The rightmost digit has the weight of 20. The second rightmost digit has the weight of 21, the next 22, the next 23 and so on. Where do the 2 come from you say? The 2 come from the radix of the number system, for binary it is 2. Binary has a radix of 2. The exponent comes from which "index" the digit have. the rightmost digit has a "index" of 0, the next 1, the next 2, and so on. So the weights of a 4-digit binary number are 8 4 2 1. To find the decimal number, we add the weights according to the binary number. So 1101b is 1*8 + 1*4 + 0*2 + 1*1 = 13.

## Convert decimal to binary

To convert decimal to binary we do something called double-dabble. We have to divide the number we want to convert by 2 (because binary has a radix of 2) multiple times, each time writing down the quotient and its remainder.

Let's say we're converting the number 14 to binary. Here is an example of how it is done:

1. We divide 14 by 2 (14 / 2). The quotient is 7.
The remainder is 0.
2. Then we divide the previously calculated quotient by 2 (7 / 2). The new quotient is 3.
The remainder is 1.
3. Then we divide the previously calculated quotient by 2 (3 / 2). The new quotient is 1.
The remainder is 1.
4. Then we divide the previously calculated quotient by 2 (1 / 2). The new quotient is 0.
The remainder is 1.
5. Now that the quotient is 0, we end the conversion. The resulting binary number is the remainder of all the previous steps read backwards. So the result is 1110b.

Just for extra fun we can convert the number 29 to binary:

1. 29 / 2 = 14, remainder 1.
2. 14 / 2 = 7, remainder 0.
3. 7 / 2 = 3, remainder 1.
4. 3 / 2 = 1, remainder 1.
5. 1 / 2 = 0, remainder 1.
6. Now that the quotient is 0, we end the conversion. The resulting binary number is the remainder of all the previous steps read backwards. So the result is 11101b.