Reader Please Note: To the best of my knowledge the information in this document is accurate. If you find any errors, have any comments, additions, or just have questions, please feel free to contact me at billetter@NetworkTechnologist.Com.
The purpose of this document is to introduce binary and hexadecimal to the PC support professional. This article will discuss the decimal and binary number systems. Then the process of converting between decimal and binary will be presented. Next hexadecimal will be presented and some examples will be given of how it is used in computers. Finally ASCII (American Standard Code for Information Interchange) will be discussed and how it is used to represent text characters as binary characters.
If you found $52,843 in the parking lot, this number would probably not confuse you. We realize that each of the digits in this number means something. For example the 3 is the number of 1 dollar bills, the 4 is the number of 10 dollar bills, the 8 is the number of 100 dollar bills, the 2 is the number of 1000 dollar bills and the 5 is the number of 10,000 bills. This can be represented in the following table:
| Decimal Number | 5 | 2 | 8 | 4 | 3 |
| Value it Represents | 10,000 | 1,000 | 100 | 10 | 1 |
| Number of 10's in that value | =10*10*10*10 | =10*10*10 | =10*10 | 10 | 1 |
Notice that each value is a multiple of 10. That is why we call it decimal, we count based upon multiples or powers of 10. For example, lets take a smaller number, 238. 238 is made up of 2 100's, 3 10's and 8 1's.
In a similar manner as representing a number in decimal, we can represent a number in binary. Binary is based upon a power of 2, which is different than decimal where the numbers are based upon powers of 10. In binary the only digits that are allowed to be used are 1 and 0. No other digits can be used! These numbers, 1 and 0 are referred to as bits, short for binary digit.
Lets use for our example the binary number 10110110. In a chart very similar to the chart used for decimal we write:
| Binary Number | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 |
| Value it Represents | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Number of 10's in that value | =2*2*2*2*2*2*2 | =2*2*2*2*2*2 | =2*2*2*2*2 | =2*2*2*2 | =2*2*2 | =2*2 | 2 | 1 |
Notice that each digit is a multiple of 2. That is why we call it binary, we count based upon multiples or powers of 2. Let's consider the same number used above in decimal, 238. In decimal that was 2 100's, 3 10's and 8 1's. In binary 238 is represented as 1 - 128, 1 -64, 1 - 32, 0 - 16's, 1 - 8, 1 - 4, 1 - 2 and 0 - 1's, or it is the binary number 11101110. We say that decimal 238 is equal to binary 11101110.
In PC support we often have to convert between binary and decimal. This is because computers use binary and we use decimal. The easiest way to do this is to use a calculator. If you run Microsoft Windows on your computer you already have a calculator built in that will do the conversion. To use this calculator, select it from the Start Menu (Start --> Programs -->Accessories --> Calculator). In the calculator, select from the View Menu the Scientific View. This gives you a calculator that can easily convert to and from Decimal, Binary, Hexadecimal and Octal. To convert 238 to binary, select the Dec radio button, type in 238 and then select the Bin radio button. The calculator will then display 11101110. To convert from binary to decimal, type in the binary number and then select the Bin radio button. You can also buy similar calculators that are portable for use in the field when you are supporting PCs.
For most of us, it will not be necessary to buy a conversion calculator. We normally don't convert from binary to decimal very often. Any conversions that we need to do, are easily memorized. But, converting from binary to decimal is a skill that is required for A+ Certification. As a result, if you plan to take this test you must know how to convert simple binary numbers to decimal . . . without a calculator! Fortunately, this is simple to do, but it requires the use of what I call "The Chart". I did not invent the chart, I don't know who did - but it is very useful for simple binary conversions.
To make the chart, you must draw a simple table with 8 columns, like this:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Then fill in the top row of the chart as shown. Start at the left with 128. Then divide 128 by 2 for 64, then divide 64 by 2 = 32, then divide 32 by 2 =16, then divide 16 by 2 =8, then divide 8 by 2 = 4, then divide 4 by 2 =2 and finally divide 2 by 2 = 1.
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
|
|
|
|
|
|
|
|
Now that you know how to make the chart, any binary number you have can be converted to decimal using a simple 3 step process. Let's try 01011001 as an example. Here is the process to convert 01011001 from binary to decimal:
Step 1 - Create the Chart
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
|
|
|
|
|
|
|
|
Step 2 - Put the binary number you are going to convert into the chart
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
0 |
1 |
1 |
0 |
1 |
0 |
0 |
1 |
Step 3 - Add up the decimal values from the first row of the chart. Any 0 digit is 0, any 1 digit is the value from the first row. For 01101001 this is calculated like this:
0 - 128's + 64 + 32 + 0 - 16's + 8 + 0 - 4's + 0 - 2's + 1 = 105
From this chart we can see that 01101001 in binary is equal to 105.
This chart works well for simple binary numbers (8 bits or less). What should you do if you have more than 8 bits - use a calculator! Although you could use a bigger chart (just expand in the other direction - 256, 512, 1024, etc), it is easier and more productive (and usually more accurate) to use a calculator.
Sometime you will have less than 8 digits. This is no problem, all you do is add 0's to the front of the number. This does not change it's value, and it allows it to fit perfectly into your chart. For example, suppose that you need to convert 110100 to decimal. Well this is onloy 6 bits and you need 8 for the chart. Add two 0's to the number. 110100 become 00110100. It is the same value, except now it fits in the chart.
Sometime we have a decimal number that we want to convert to binary. Again for large numbers the calculator is preferred. However, for numbers less than or equal to 255, we can use the chart. For example lets convert 210 to binary. Here is the process:
Step 1 - Create the Chart
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
|
|
|
|
|
|
|
|
Step 2 - For each number in the top row of the chart, starting with 128, see if it divides into the decimal number. If it does, put a 1 in the second row of the chart and continue with the remainder. For 210 this is the following
Does 128 go into (divide into) 210? Yes, with a remainder of 82. So, put a 1 in the chart like this:
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
1 |
|
|
|
|
|
|
|
Now, working with the remainder continue to the next number. For our example, does 64 go into 82. Yes, with a remainder of 18. Now the chart looks like this:
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
1 |
1 |
|
|
|
|
|
|
Continuing, does 32 go into 18? The answer is no. For a no answer, we put a 0 in the table. The table now becomes:
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
1 |
1 |
0 |
|
|
|
|
|
Does 16 go into 18? Yes, remainder 2. Put a 1 in the chart.
Does 8 go into 2? No. Put a 0 in the chart.
Does 4 go into 1? No. Put a 0 in the chart.
Does 2 go into 2? Yes, remainder 0. Put a 1 in the chart.
Does 1 go into 0? No. Put a 0 in the chart.
Our chart finally becomes:
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
1 |
1 |
0 |
1 |
0 |
0 |
1 |
0 |
So, from our process, 210 becomes 11010010 binary.
Most of the world uses the Metric System. From the metric system we are used to terms like kilometers or megawatts. In the metric system we know that a kilometer is 1000 meters and that a megawatt is 1,000,000 watts. However, whenever we deal with binary numbers, kilo and mega have a different meaning. In binary, kilo is 1024 and mega is 1024 kilo's or 1048576.
In computers, this use of mega, kilo and other pre-fixes is restricted to binary. This means when referring to storage of groups of 8 bits (known as bytes). We commonly use this term with disk storage and memory (ram and rom) storage. It is not used for non-binary storage, such as a modem. A 56Kb modem is 56,000 bits per second. But 1 Megabyte of storage is 1024 Kilobytes of storage or 104876 bytes of storage.
Here are the more common pre-fixes, and their values for binary storage:
| Prefix | Value |
|---|---|
1 Byte |
8 Bits |
1 KiloByte (KB) |
1024 Bits |
1 MegaByte (MB) |
1024 KiloBytes |
1 GigaByte (GB) |
1024 MegaBytes |
1 TeraByte (TB) |
1024 GigaBytes |
1 PetaByte (PB) |
1024 GigaBytes |
1 ExaByte (EB) |
1024 Petabytes |
Because of the power processors that we have available to us today, and the large number of bits they can process at one time, even with calculators binary is very difficult to use. So, we usually use hexadecimal numbers to represent large binary numbers. This results in less digits.
Hexadecimal is based on powers of 16. This makes converting hexadecimal very complicated - it does require the use of a calculator for most problems. But as a PC support professional you still need to know how hexadecimal works. The hexadecimal numbering system uses 16 digits. Looking at your keyboard, this poses a problem, since we only have 10 digits. The hexadecimal folks solved this problem by using the letters A - F to represent 6 digits. Here a table that counts from 0 to 15 using decimal, binary and hexadecimal:
| Decimal | Binary | Hexadecimal |
|---|---|---|
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 |
How does hexadecimal make using binary more convenient? Here is an example. Suppose that we are talking about memory in a PC. One of the most important areas of memory for 16 bit programs is between 640K and 1 MB. Here is decimal, binary and hexadecimal:
| Decimal | Binary | Hexadecimal |
|---|---|---|
640K |
10100000000000000000 |
A0000 |
1 MB* |
11111111111111111111 |
FFFFF |
Notice that the hexadecimal representation uses less digits and is easier to use. It does require a calculator however to convert. (* actually the value we are using is 1 byte less than 1 MB, but it is easier to write 1 MB in decimal for this example)
The American Standard Code for Information Interchage (ASCII) is a very popular method of representing text as binary numbers. It is a binary code that represents all printable and many non-printable characters. There are 2 common versions of ASCII, 7 bit standard ASCII and 8 bit extended ASCII. Here is the code table for 7 bit standard ASCII:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | |
| 0 | NUL | SOH | STX | ETX | EOT | ENQ | ACK | BEL | BS | TAB | LF | VT | FF | CR | SO | SI |
| 1 | DLE | DC1 | DC2 | DC3 | DC4 | NAK | SYN | ETB | CAN | EM | SUB | ESC | FS | GS | RS | US |
| 2 | SPACE | ! | " | # | $ | % | & | ` | ( | ) | * | + | ' | - | . | / |
| 3 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | : | ; | < | = | > | ? |
| 4 | @ | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O |
| 5 | P | Q | R | S | T | U | V | W | X | Y | Z | [ | \ | ] | ^ | _ |
| 6 | ` | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o |
| 7 | p | q | r | s | t | u | v | w | x | y | z | { | | | } | ~ | DEL |
The way that you read this chart is the left hand column is the left most 4 bits and the top row is the 4 right bits in the 7 bit string. Using this key, the letter "e" is 65 in hexadecimal or 01100101 in binary. Since standard ASCII is a 7 bit code, all of these characters start with 0 in binary. Note that some of these characters may not be familiar because they are used with teletypewriter terminals. Some of the unfamiliar codes are:
NUL - NULL
SOH - Start of Heading
STX - Start of Text
ETX - End of Text
EOT - End of Transmission
ENQ - Enquiry
ACK - Acknowledgement
BEL - Bell
BS - Backspace
TAB - Horizontal Tab
LF - Linefeed
VT - Vertical Tab
FF - Formfeed or New Page (NP)
CR - Carriage Return
SO - Shift Out
SI - Shift In
DLE - Data Link Escape
DC1 - Device Control 1
DC2 - Device Control 2
DC3 - Device Control 3
DC4 - Device Control 4
NAK - Negative Acknowledgement
SYN - Synchronous Idle
ETB - End of Transmission Block
CAN - Cancel
EM - End of Medium
SUB - Substitute
ESC - Escape
FS - File Separator
GS - Group Separator
RS - Record Separator
US - Unit Separator
DEL - Delete
Extended ASCII is an 8 bit code that uses graphics symbols in addition to the above standard ASCII characters. The graphics symbols are simple line characters that when combined can make fairly sophisticated drawings. This character set was popular in the early PC days before the graphics capable printers that we now have. All printers back then could only print characters and not pictures. The extended character set was used to print pictures, not quite WYSIWYG (what you see is what you get) that we are used to today.