Binary and Hexidecimal Conversion Tutorial
Binary and Hexidecimal Conversion Tutorial
In electronics, a 0 is off (usually 0 Volts) and 1 is on (usually 5 Volts). All computer data is
composed of 1s and 0s. Each individual 1 or 0 is a bit. Four bits is a nibble. Eight bits is a
byte. From there we have kilobytes, megabytes, etc. Since everything is a series of 1s and
0s, the CPU has to perform every calculation in binary. But before any operations are done,
numbers have to first be converted into base 2.
But before diving into the binary number system and conversions, let's first see how things
work in our decimal system.
Let's just pick a number...like 9345. How do we get this? Remember when I mentioned we
use base 10? In math the base is a number that's raised to a power (another name for
power is exponent). For example 34 is 3 raised to the 4th power, which means you multiply 3
times itself 4 times (3 * 3 * 3 * 3).
We have what's called a place value system. Each individual number holds a particular
numerical position. We get these positions by using 10 raised to different powers. Start with
the number on the right.
So looking at 9345, the right-most number 5 is in the ones place (10º = 1). The 4 is in the
tens place (10¹ = 10). The 3 is in the hundreds place (10² = 100), and the 9 is in the
thousands place (10³ = 1000). This is true for any number. Now the larger the number the
more place values (ten thousands, hundred thousands, etc.), but I'm keeping it short in this
example. So we have:
If you take each number, multiply it by its place value, & add the results, you get 9345.
This method is used in base 2 except rather than the ones place, tens place, hundreds
place, thousands place, etc. you have: ones place (2º), twos place (2¹), fours place (2²), and
eights place (2³), etc.
Using the base 10 example just above, the number 10112 is like this:
It's the same process for any number system. And remember, the computer number system
always uses binary. So now that you have a basic understanding of place values, it's time to
start converting!
For example if we want to know what 1101000112 is in our number system (base 10) we do
the following:
We usually start on the right. With each number, you raise 2 to its power then multiply the
result by the binary digit. When you're done, add all the results together and that is the
number in base 10.
Successive division requires dividing continuously by the base you're converting to until the
quotient equals 0. The remainders compose the answer.
The most significant bit is the left number in the answer and the least significant bit is on the
right end giving us an answer of: 11010000112
Binary digits are usually grouped by 4, 8, 16, etc. so we can place a couple of 0s on the left
to give us three groups of four. This does not change the answer.
0011 0100 00112
We just looked at the successive division method of converting from decimal to binary. The
other method is subtracting values. With this method you keep subtracting until you reach 0.
Let's convert 165 to binary.
Notice a 1 is only placed under the highest value that can be subtracted from a number.
Everything else is automatically a 0 giving us an answer of: 101001012.
Hexadecimal:
The hexadecimal (hex for short) number system uses 16 digits to form all other numbers.
The purpose of using hex is for human understanding. Computers always work in binary (0s
and 1s). To have a long series of binary digits gets complicated, so programmers had to
come up with a more simplfied way to represent them. Hex groups binary numbers into 4 bit
packages so to speak. One hex digit represents four bits (called a nibble). Hexadecimal
numbers have a subscript 16 or H behind them (D316 or D3H). Because single characters
must be used, the letters A, B, C, D, E, F represent 10-15. Remember, when dealing with
number systems, we always start with 0. So we have 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E,
F. Memory locations are listed as hex values, and many times when you get an error
message, your OS (operating system) will show you the location.
F6AH - 12 bits
BH - 4 bits
78H - 6 bits
We're done since we can't divide 1 by 16 and that leaves us with a remainder of 1. When
writing the answer the LSD is always on the right and the MSD on the left. The answer is:
1F516
Binar
Decimal Hex
y
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F