Binary, Hexadecimal and Octal Number Systems
 External Source! This page was originally written for the TI-Basic Developer wiki. Credits go to: Mapar007 (creator), James Kanjo, RandomProductions and DarkerLine. (put up: 10/7/08)

# What?

The binary number system is a number system only using 2 values: 0 and 1 (Lat. “bis” means “twice”). This system is ideal for computer science, 0 representing “no current” and 1 representing “current”.

The hexadecimal number system consists of 16 values: 0,1,2,3,4,5,6,7,8,9,A,b,C,d,E and F (Greek “hexa kai deka” means 16), respectively 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14 and 15. Note that the “b” and “d” are written in lowercase, to make it easier to display on a digital display.

The octal number system uses 8 values (0,1,2,3,4,5,6,7). The name is -again- derived from Greek/Latin: okto(GR)/octo(lat.).

# How?

Now you might be asking yourself how to read these numbers. Well, that’s not so difficult. First, I’ll give a general mathematical explanation which can be fit into one formula:

(1)
$$V = vB^P$$

In human language: the value of the cipher in the number is equal to the value of the cipher on its own multiplied by the base of the number system to the power of the position of the cipher from left to right in the number, starting at 0. Read that a few times and try to understand it.

Thus, the value of a digit in binary doubles every time we move to the left. (see table below)

From this follows that every hexadecimal cipher can be split up into 4 binary digits. In computer language: a nibble. Now take a look at the following table:

Binary Numbers 8 4 2 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 2 2 0 0 1 1 3 3 0 1 0 0 4 4 0 1 0 1 5 5 0 1 1 0 6 6 0 1 1 1 7 7 1 0 0 0 8 8 1 0 0 1 9 9 1 0 1 0 A 10 1 0 1 1 B 11 1 1 0 0 C 12 1 1 0 1 D 13 1 1 1 0 E 14 1 1 1 1 F 15

Another interesting point: look at the value in the column top. Then look at the values. You see what I mean? Yeah, you’re right! The bits switch on and off following their value. The value of the first digit (starting from the right), goes like this: 0,1,0,1,0,1,0,1,0,1,… Second digit: 0,0,1,1,0,0,1,1,0,0,1,1,0,0… Third digit (value=4): 0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,… And so on…

Now, what about greater numbers? Therefore we’ll need an extra digit. (but I think you figured that out by yourself). For the values starting from 16, our table looks like this:

Binary Numbers 16 8 4 2 1 1 0 0 0 0 10 16 1 0 0 0 1 11 17 1 0 0 1 0 12 18 1 0 0 1 1 13 19 1 0 1 0 0 14 20 1 0 1 0 1 15 21 1 0 1 1 0 16 22 1 0 1 1 1 17 23 1 1 0 0 0 18 24 1 1 0 0 1 19 25 1 1 0 1 0 1A 26 1 1 0 1 1 1B 27 1 1 1 0 0 1C 28 1 1 1 0 1 1D 29 1 1 1 1 0 1E 30 1 1 1 1 1 1F 31

For octals, this is similar, the only difference is that we need only 3 digits to express the values 1->7. Our table looks like this:

Binary Numbers 4 2 1 0 0 0 0 0 0 0 1 1 1 0 1 0 2 2 0 1 1 3 3 1 0 0 4 4 1 0 1 5 5 1 1 0 6 6 1 1 1 7 7

# Conversion.

In the latter topic I explained the logic behind the binary, hexadecimal and octal number systems. Now I’ll explain something more practical. If you fully understood the previous thing you can skip this topic.

## From decimal to binary

• Step 1: Check if your number is odd or even.
• Step 2: If it's even, write 0 (proceeding backwards, adding binary digits to the left of the result).
• Step 3: Otherwise, if it's odd, write 1 (in the same way).
• Step 4: Divide your number by 2 (dropping any fraction) and go back to step 1. Repeat until your original number is 0.

An example:
Convert 68 to binary:

• 68 is even, so we write 0.
• Dividing 68 by 2, we get 34.
• 34 is also even, so we write 0 (result so far - 00)
• Dividing 34 by 2, we get 17.
• 17 is odd, so we write 1 (result so far - 100 - remember to add it on the left)
• Dividing 17 by 2, we get 8.5, or just 8.
• 8 is even, so we write 0 (result so far - 0100)
• Dividing 8 by 2, we get 4.
• 4 is even, so we write 0 (result so far - 00100)
• Dividing 4 by 2, we get 2.
• 2 is even, so we write 0 (result so far - 000100)
• Dividing 2 by 2, we get 1.
• 1 is odd, so we write 1 (result so far - 1000100)
• Dividing by 2, we get 0.5 or just 0, so we're done.
• Final result: 1000100

## From binary to decimal

• Write the values in a table as shown before. (or do so mentally)
• Add the value in the column header to your number, if the digit is turned on (1).
• Skip it if the value in the column header is turned off (0).
• Move on to the next digit until you’ve done them all.

An example:
Convert 101100 to decimal:

• Highest digit value: 32. Current number: 32
• Skip the "16" digit, its value is 0. Current number: 32
• Add 8. Current number: 40
• Add 4. Current number: 44
• Skip the "2" and "1" digits, because their value is 0.

THIS IS ONLY ONE OF THE MANY WAYS!

• Convert your decimal number to binary
• Split up in nibbles of 4, starting at the end
• Look at the first table on this page and write the right number in place of the nibble

(you can add zeroes at the beginning if the number is not divisible by 4, because, just as in decimal, these don’t matter)

An example:

• First, we convert to binary (see above). Result: 100111
• Next, we split it up into nibbles: 0010/0111 (Note: I added two zeroes to clarify the fact that these are nibbles)
• After that, we convert the nibbles separately.
• Final result: 27

*Check the formula in the first paragraph and use it on the ciphers in your hexadecimal number. (this actually works for any conversion to decimal notation)

An example:
Convert 1AB to decimal:

• Value of B = 160×11. This gives 11, obviously
• Value of A = 161×10. This gives 160. Our current result is 171.
• Value of 1 = 162×1. This gives 256.
• Final result: 427

## From decimal to octal

• Convert to binary.
• Split up in parts of 3 digits, starting on the right.
• Convert each part to an octal value from 1 to 7

Example: Convert 25 to octal

• First, we convert to binary. Result: 11001
• Next, we split up: 011/001
• Conversion to octal: 31

## From octal to decimal

Again, apply the formula from above

Example: convert 42 to decimal

• Value of 2=80×2=2
• Value of 4=81×4=32
• Result: 34

# Fun Facts

OK, these may not be 100% "fun", but nonetheless are interesting.

• Do you tend to see numbers beginning with 0x? This is common notation to specify hexadecimal numbers, so you may see something like:
0x000000
0x000002
0x000004


This notation is most commonly used to list computer addresses, which are a whole different story.
• This is pretty obvious, but you can "spell" words using hexadecimal numbers. For example:
• CAB = 3243 in decimal notation.

# End

Did you understand everything? If you think so, test yourself:

Bin Dec Hex
3A
76
101110
88
1011110
47

Make some exercises yourself, if you want some more.