Base 10 (Decimal)
We live in a decimal world, meaning we live in a base 10 world. In our number system, there are ten digits, 0-9. Once we reach the maximum value (9) in a column, we roll it over to the start (0), and increment the next column to the left.
_8, _9, 10, 11,...,18, 19, 20, ...
The decimal number system, like all number systems, has place values. Place values are the standard unit value for each column in a number. Place value increase from right to left. The place values are determined by the powers of the base, starting at 0. The number 123,456 can be represented with place values as follows:
1 | 2 | 3 | 4 | 5 | 6 |
100000 | 10000 | 1000 | 100 | 10 | 1 |
105 | 104 | 103 | 102 | 101 | 100 |
Base 2 (Binary)
Base 2, or binary, is the language of computers. This is because binary has only two possible value, 0 and 1. Computers can use this because 0 and 1 represent states of a circuit as off and on, respectively. A single binary digit, a 0 or 1, is called a bit. When eight bits are put together, you get a byte and so on.
Base 2 follows all of the same rules as base 10: place values start with a power of 1 and increase from left to right. The only differences are:
- The base used in the columns is 2
- There are only two digits, 0 and 1
So, the columns of the binary counting system are:
An example of a binary number is 101101
2.
Converting Binary to Decimal
To calculate the value of a decimal value using place values we multiply the digit in the column by the value of the column, so 123456
10 evaluates to
1x100000 + 2x10000 + 3x1000 + 4x100 + 5x10 + 6x1 = 100000 + 20000 + 3000 + 400 + 50 + 6 = 123,456
Converting binary to decimal follows the same process. We take the digit in the column and multiply by the value of the column. Then, we add each value together. So, given 101101
2, we see
1 | 0 | 1 | 1 | 0 | 1 |
25 | 24 | 23 | 22 | 21 | 20 |
32 | 16 | 8 | 4 | 2 | 1 |
101101 = 1x32 + 0x16 + 1x8 + 1x4 + 0x2 + 1x1 = 32 + 0 + 8 + 4 + 0 + 1 = 45
Converting Decimal to Binary
If I want to break a base 10 number up into place values, I find the largest place value that goes into the number. For example, given the number 4562, the largest place value that goes into 4562 is 1000. It goes in 4 times, so we place a 4 in the 1000's columns.
This leaves a remainder of 562. The next highest column that goes in is 100, going in 5 times and leaving a remainder of 62.
This process continues until we run out of columns.
Again, we use the same process to move from decimal to binary. When working with the value 279
10, we start with the highest binary place value that is less than 279. The binary columns are 1, 2, 4, 8, 16, 32, 64, 128, 256... So, we start with the 256 column, also known as 2
8. With binary, the column is either on (1) or off (0). Since 256 is lessthan 279, the 256 column is on and we are left with a remainder of 23.
1 |
27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
256 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Next, we check the next highest column value. It happens to be 128, which is not less than our remainder of 23, so it is turned off (0).
1 | 0 |
27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
256 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
The following columns of 64 and 32 are also above our remainder of 23, so they are also turned off.
1 | 0 | 0 | 0 |
27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
256 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
The next column is the 16's column. This is less than 23, so it is turned on. This process continues until we get to the ones column.
1 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 1 |
27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
256 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
So, our final value is 100010111.
Real World Applications
On a computer keyboard, when a key is pressed, a series of eight circuits (1 byte) are turned on/off, sending a binary value to the computer. The computer, then uses the American Standard Code for Information Interchange (ASCII) to convert that binary value to the corresponding character on the keyboard. For example, in ASCII code, the letter 'A' has the value 65, which in binary is 01000001. Working with ASCII code is possible for us to encrypt/decrypt byte code and turn it into letters. When there is more than one byte of information, it is important to break the bits into bytes from right to left. This is because leading zeros on a binary string can be left off. For example, 0110 is the same as 110.
Example:
Translate to english: 100100001101001
2
- Break bits into bytes from right to left: 1001000 | 01101001
- Convert binary to decimal. 1001000 = 72; 01101001 = 105
- Use the ASCII chart to converto to letters: 72 = 'H'; 105='i';
The resulting message is Hi.