Expert Reference Series of White Papers
Number Systems Decoded Binary, Decimal, and Hexadecimal
1-800-COURSES
www.globalknowledge.com
Number Systems Decoded Binary, Decimal, and Hexadecimal George Mays, CISSP, CCNA, A+, Security+, Network+
Introduction In many IT-related fields of study, it is extremely valuable to have a good understanding of the number systems that are often encountered. For many people, not appreciating things such as binary and hexadecimal is a stumbling block that keeps them from advancing their knowledge. If you cringe a little bit at the mention of these topics, then this white paper is definitely for you. Of course, you may have learned these things many years ago, and you would like a refresher course on number systems. Or, perhaps you are tired of not understanding the gobbledygook that appears in file dumps, in routing tables, and in your protocol analysis tools. Whatever your particular reasons for reading this white paper are, I welcome your attention.
What You Will Learn We all have an instinctive feel for what numbers are. They are used on a regular basis to identify a particular house on a street, a channel on the television, or how much to pay for an item. Numbers are used in a variety of ways; they are most often used to convey a quantity to someone—twelve chairs, for instance. Numbers are also used in verbal codes, such as 10-4 (ten-four). Sometimes they are part of an address (such as zip codes). Despite the intended use, numbers are constructed in the same way and follow the same basic set of rules. Understanding those rules is the key to advancing your appreciation of numbers. Several systems of numbers are commonly used in computing circles. These are the decimal, binary, and hexadecimal number systems. These alternative number systems have three things in common: a base number (sometimes called a radix); a set of digits or numerals to work with; and a positional notation in which the position of a given digit affects how it is interpreted. Each number system employs: • A Base or radix value around which the number system is organized • A set of Digits or symbols used in forming numbers • A Positional Notation meaning that the position in which a digit appears conveys information about the significance or weight of that digit
Copyright ©2007 Global Knowledge Training LLC. All rights reserved.
Page 2
Name
Base
Digits
Decimal
10
0, 1, ...9
Binary
2
0, 1
Hexadecimal
16
0, ...9, A, ...F
Figure A Number System Names, Bases, and Digits
Each number system has a name: Decimal, Binary, and Hexadecimal. Since “hexadecimal” does not flow trippingly off our tongues, we often simply say “Hex” instead. The decimal number system is encountered most commonly. This is the number system that everyone learns as a child. As a result, people are most comfortable with decimal. Everything in a digital world reduces to binary form – everything! The information stored on your disk drive is stored in a binary form. The information transported across your network is transmitted in a binary form. Binary is the frank language of computers. And while people may not be as comfortable with binary, computers love it. Hexadecimal was invented to intimidate those who are new to information technologies. It is the number system that is used to confuse students. Just kidding, hex is used as a kind of shorthand for binary. Binary numbers tend to be rather long and cumbersome to type, write down, or say. So hex is used to convey the same information in a compact fashion. It turns out to be very simple to convert from hex to binary – you will learn how. The “base” value for a number system is simply the number around which the system is organized. Everything orbits around the value 10 for base 10 (decimal) numbers. For example, there are ten digits to work with. Notice that base 2 (binary) numbers have only two digits that can be used. You do see the pattern, don’t you? If base 10 has ten digits to work with, and base 2 has two digits to work with, then base 16 must have – how many digits? You guessed it, sixteen. They are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. The sixteen hex digits sometimes leave people scratching their head because we use the symbols A, B, C, D, E, and F as digits. These symbols simply represent quantities, as follows: Hexidecimal Digit Decimal Value These symbols are letters of the alphabet. You know that; I know that. However, in hexadecimal numbers, they are digits, perfectly good digits. Someone might point out to you that there are 3 windows in the classroom. The digit 3 conjures up something in your brain – the notion of the quantity 3. In like manner, I could note that there are B desks in the classroom. That should make you think of the quantity 11, hence 11 desks are present.
Copyright ©2007 Global Knowledge Training LLC. All rights reserved.
A
10
B
11
C
12
D
13
E
14
F
15
Figure B. Hex Digit Values in Decimal
Page 3
Base 10 Let’s consider a simple base 10 number, 1585. The number is structured in a very orderly way. To begin with, note that the digits all come from the decimal symbol set (0, 1, 2, 3, 4, 5, 6, 7, 8, and 9) and that the symbol 5 appears twice in the number. We us the term “positional notation” to reflect the fact that the 5 appearing in the rightmost position is interpreted differently than the one appearing two positions to the left. That is to say that the position in which a digit appears has everything to do with the significance or weight that we attach to it. In this case the rightmost 5 implies 5 ones and that to the left implies 5 hundreds.
1000s
100s
8s
1s
1
5
8
5
1000
500
80
5
= 1585
Figure C. Positional Notation
Take a look at Figure C. It is obvious to most people how decimal values are organized. The rightmost position is the “ones place.” To the left is the “tens place.” To the left again is the “hundreds place,” and so on. Notice that each “place” or position carries a weight 10 times the one to its right. (Just what you’d expect? This is the base 10 number system, after all.) A careful analysis of our example value reveals that the number 1585 is intended to convey to us, as readers of the number, a quantity that is comprised of 1 thousand, 5 hundreds, 8 tens, and 5 ones. That is pretty simple, right? There are no surprises here. This is stuff from the third grade in elementary school. But what about the other number systems? They must be different somehow.
Base 2 Let us now examine a binary example, 1001. Start by noting that the digits come from the smaller binary symbol set, just 0s and 1s. And, in a manner similar to the previous example, the symbol 1 appears twice. The rightmost position in a binary number is the ones place, as it was in the decimal example. (See Figure D.) But as we progress to the left, each position carries a weight that is 2 times the one on its right. Thus we observe the ones place, twos place, fours place, eights place, and so on.
8s
4s
2s
1s
1
0
0
1
8
0
0
1
=9
Figure D. Binary Notation
So in binary values you have only 2 digits to work with, zeroes and ones, and the “places” in the numbers are each weighted 2 times the position to their right. That’s why it is called the base 2 numbering system. Analyzing our example value (1001), we discover that this number is intended to convey to the reader a quantity comprised of 1 eight and 1 one, or 9 (in decimal).
Base 16 Now consider a hexadecimal example, 12A. Just as with the other number systems, the digits come from the allowable symbol set, in this case 0 through 9 and A through F.
Copyright ©2007 Global Knowledge Training LLC. All rights reserved.
Page 4
A few observations are in order before proceeding. First, 4096s 256s 16s 1s some people seem to think that there is some difference between a lower case “a” and an upper case “A.” There 1 2 A is not. You will see both cases regularly and the differ256 32 10 = 298 ence does not matter. Second, as noted previously, some people cringe seeing letters of the alphabet in numbers. Figure E. Hex Notation Put your confusion aside. Just as the regular-old-everyday digit 5 makes you think of the number of fingers on your hand, the hex digit C should make you think of the number of doughnuts that come in a package. (Of course, a baker’s dozen would be a hex D.) Consider Figure E. The rightmost position is again the 1s place. What is different is that as you move to the left, each position carries a weight that is 16 (get it, base 16) times the position on the right. So you end up with a progression like 1, 16, 256, 4096, and so on. Our example value then, 12A, denotes 1 two-hundred-fifty-six, 2 sixteen’s, and A ones. With a little quick mental gymnastics one realizes the A ones means 10 (decimal) ones to mere mortals. So this hex value conveys the notion of 256 plus 32 plus 10, or the quantity 298 decimal.
Intermediate Summary You have learned that three number systems are used commonly in IT: decimal; binary; and hexadecimal. Also, these number systems are structured in a similar manner. They each have a “base” value of 10, 2, and 16, respectively. And, each has a limited symbol set (digits) that can be used in constructing numbers. For decimal the set consists of the digits 0…9, for binary there are only 0s and 1s, and for hex the digits 0…9 and A…F are used. Each of the number systems employs a positional notation in which a given digit’s position within a number dictates the weight that we associate with it. The rightmost position is always the 1s place. As you move to the left, the positions carry a weight that is the base value times its right-hand neighbor. The progressions 1, 10, 100, and so on appear for decimal numbers. With binary numbers we see a progression like 1, 2, 4, 8, 16, 32, etc. And for hex we observe the progression 1, 16, 256, 4096, and so on.
Recognizing the Number System How do you know whether the value 101 is decimal, binary, or hex? You don’t, unless there is additional clarification provided to you. The number system being used is very often conveyed by the context in which you observe the number. By default, we tend to assume that a number is decimal unless otherwise indicated. But if you were reading a paper on binary masking (whatever that is) you might reasonably assume that the value is binary. You get the idea. Mathematicians use subscripts to indicate the number system. So if you see 10110 then you are dealing with 101 base 10, decimal. The value 1012 means that this is a binary (base 2) value. And, as you would expect, 10116 implies a hexadecimal (base 16) value.
Copyright ©2007 Global Knowledge Training LLC. All rights reserved.
Page 5
Programmers have various notations that you will encounter as well. It is extremely common to encounter a number like 0x101. The 0x prefix is C-programmer-speak for a hex constant. So this pops up a lot. Assembly language programmers have their own notations. For example, in such a program you might encounter 101h, meaning a hex value. Similarly, 101b implies a binary value..
Decimal to Binary Conversion Converting a decimal value to binary is like making change at a cash register. Except, instead of using 1, 10, and 100 dollar bills you use “Bin-o-Bucks”*. The denominations are 1, 2, 4, 8, 16, and so on. Make yourself a cheat-sheet like this: 128
64
32
16
8
4
2
1
How would you “pay” somebody 18 in bin-o-bucks? You would give them 1 sixteen and 1 two. Like this: 128
64
32
16 1
8
4
2 1
1
And since you are not paying out any eights, fours, or ones, just put a zero in those positions to indicate that fact. You end up with: 128
64
32
16 1
8 0
4 0
2 1
1 0
The binary value 10010 represents the decimal value 18. Easy. Try it again by converting the value 3710 to bino-bucks. (Here is your cheat-sheet.) 128
64
32
16
8
4
2
1
Now check your result. To pay out 37 you would use 1 thirty-two, 1 four, and 1 one. Get it? 32 + 4 + 1 = 37. You answer should look like: 128
64
32 1
16 0
8 0
4 1
2 0
1 1
Do not make this more complicated than it is. Conversion from decimal to binary is, in fact, this simple. If you practice just a little bit, then you can easily become quite good at this.
Binary to Decimal Conversion Simply extend the change-making analogy that was just described. For example, if someone just handed you an 8 dollar bill and a 4 dollar bill then they just gave you: 128
64
32
16
8 1
4 1
2 0
1 0
And 8 + 4 is 12. So a binary 1100 is the representation for a decimal 12. Copyright ©2007 Global Knowledge Training LLC. All rights reserved.
Page 6
Try this again for yourself. The customer just handed you a 64, an eight and a two. Here is your cheat sheet: 128
64
32
16
8
4
2
1
16 0
8 1
4 0
2 1
1 0
Your result should look like this: 128
64 1
32 0
64 + 8 + 2 = 74. So you just received 74 bucks.
Decimal to Hexadecimal Stick with the change-making analogy. Only replace the bin-o-bucks with “Hex-A-Bucks”*. The denominations of the bills are 1s, 16s, 256s, and 4096s. Your cheat-sheet looks like this: 4096
256
16
1
If you had to pay out 3510 dollars, that would call for the use of two 16s and three 1s. 4096
256
16 2
1 3
So the value 23 is the hex representation of the decimal value 35. Try your hand at this. You need to pay out 2510 in hex-a-bucks. What do you get? Here is your cheat-sheet: 4096
256
16
1
Check your answer. You should have gotten this: 4096
256
16 1
1 9
The answer is one 16 plus nine 1s. 16 + 9 = 25.
Hexadecimal to Decimal Extend the hex-a-bucks analogy from the previous exercises to convert in the opposite direction, from hex to decimal this time. Start with you hex cheat-sheet: 4096
256
16
1
Copyright ©2007 Global Knowledge Training LLC. All rights reserved.
Page 7
Now, let’s say that you are asked to convert 5416 to base 10. Plug 54 into your cheat-sheet. You get: 4096
256
16 5
1 4
That is five 16s and four 1s. 5 x 16 = 80, add the 4 x 1, you get 84 decimal. Can you do this one: 1E16 = ?10. Here is your cheat sheet: 4096
256
16 1
1 E
That would be 1 sixteen and E ones. Recall that the symbol E depicts the quantity 14 in decimal. So that is one 16 and 1410 1s; 16 + 14 is 30 decimal.
Hexadecimal to Binary Hex to binary is very easy. Conversion is done using a simple substitution technique. Each hex digit converts to four binary digits. Here is what the hex digits look like in binary: Hex 0 1 2 3
Binary 0000 0001 0010 0011
Hex 4 5 6 7
Binary 0100 0101 0110 0111
Hex Binary 8 1000 9 1001 A 1010 B 1011
Hex C D E F
Binary 1100 1101 1110 1111
Do you understand where these numbers come from? Let’s take a couple of them and analyze them to be sure that you appreciate what is going on here, starting with the hex 6. What does 616 look like in binary? 8 0
4 1
2 1
1 0
Notice the 4 and the 2 bit (binary digit) positions are set to 1. The other positions are 0. One 4 plus one 2 equals 6. Or how about the 916 table entry? In binary it looks like: 8 1
4 0
2 0
1 1
That’s one 8 plus one 1, or 9. Now that you know how this substitution table was constructed, let’s convert a sample hex value, how about B8, to binary. Simply write binary 1011 in place of the hex B followed by binary 1000 in place of the 8. You get 1011 1000 binary. (I put a space in there for clarity – binary numbers don’t actually have spaces in them.)
Copyright ©2007 Global Knowledge Training LLC. All rights reserved.
Page 8
Hex value to be converted: Substitute 1011 for hex B: Substitute 1000 for hex 8:
B8 1011 1011
8 1000
Try another example. 4F116 = ?2. In place of the 4 write 0100, in place of the F write 1111, and in place of the 1 write 0001. You get 0100 1111 0001. Hex value to be converted: Substitute 0100 for hex 4: Substitute 1111 for hex F: Substitute 0001 for hex 1:
4F1 0100 0100 0100
F1 1111 1 1111 0001
Binary to Hexadecimal Converting a binary value to hex is similarly easy. Just reverse the substitution process described above. Working from right to left in the binary value, substitute one hex digit for each group of four binary digits. An example is the best way to appreciate this. Binary value to be converted: Identify groups of four bits: Substitute hex 6 for 0110: Substitute hex B for 1011:
10110110 1011 0110 6 B 6
If the number of binary digits (bits) is not a multiple of four, then just pad it on the left with additional zeroes. For example: Binary value to be converted: Identify groups of four bits: Pad the left with zero bits: Substitute hex 6 for 0110: Substitute hex B for 1011: Substitute hex 2 for 0010:
1010110110 10 1011 0010 1011 2
B
0110 0110 6 6
Helpful Tools for Working with Number Systems There is no shortage of tools to help you work with the number systems. Though hardly the best tool, the Windows Calculator can be useful. On a Windows system, begin at the Start button, choose All Programs, then Accessories. Finally, choose Calculator. The familiar Windows Calculator will pop up. You are probably used to the wimpy balance-your-checkbook mode that appears above. But if you pick the View pull-down menu and select Scientific, the fancier calculator features are revealed. Figure F. Calculator
Copyright ©2007 Global Knowledge Training LLC. All rights reserved.
Page 9
Toward the upper left of the calculator you will see a group box that contains four radio buttons: Hex, Dec, Oct, and Bin. The Bin button has been clicked in the figure above and a binary value entered into the calculator: 1010110110.
Figure G. Hex Calculator
Clicking on the Hex button, the calculator converts the binary value to hex: 2B6. You can use this technique to convert between any of the supported number systems. If you are curious, Oct stands for the octal, or base 8, number system.
Figure H. Hex Conversion
Another tool that you might like is my Number Converter. You can obtain this from my website: HYPERLINK "http://www.gwmays.com" www.gwmays.com. Just follow the link to Number Converter Version 2. It can be downloaded as a .zip file or, more conveniently, as a self-extracting zip, the .exe. This tool has only one input field at the upper left. The program converts any number that you enter here to each of the number systems that we learned about. A note: the Number Converter “guesses” what kind of value you entered; you may have to click the Type of Input Value button to correct the Number Converter if it guesses wrong.
Figure I. Number Converter 2.0
Another tried and true tool is a conversion chart. The conversion chart on the next page covers all values between 0 and 255 decimal.
Copyright ©2007 Global Knowledge Training LLC. All rights reserved.
Page 10
Decimal
Binary
Hex
Decimal
Binary
Hex
Decimal
Binary
Hex
Decimal
Binary
Hex
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0000 0000 0000 0001 0000 0010 0000 0011 0000 0100 0000 0101 0000 0110 0000 0111 0000 1000 0000 1001 0000 1010 0000 1011 0000 1100 0000 1101 0000 1110 0000 1111
00h 01h 02h 03h 04h 05h 06h 07h 08h 09h 0Ah 0Bh 0Ch 0Dh 0Eh 0Fh
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
0100 0000 0100 0001 0100 0010 0100 0011 0100 0100 0100 0101 0100 0110 0100 0111 0100 1000 0100 1001 0100 1010 0100 1011 0100 1100 0100 1101 0100 1110 0100 1111
40h 41h 42h 43h 44h 45h 46h 47h 48h 49h 4Ah 4Bh 4Ch 4Dh 4Eh 4Fh
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
1000 0000 1000 0001 1000 0010 1000 0011 1000 0100 1000 0101 1000 0110 1000 0111 1000 1000 1000 1001 1000 1010 1000 1011 1000 1100 1000 1101 1000 1110 1000 1111
80h 81h 82h 83h 84h 85h 86h 87h 88h 89h 8Ah 8Bh 8Ch 8Dh 8Eh 8Fh
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
1100 0000 1100 0001 1100 0010 1100 0011 1100 0100 1100 0101 1100 0110 1100 0111 1100 1000 1100 1001 1100 1010 1100 1011 1100 1100 1100 1101 1100 1110 1100 1111
C0h C1h C2h C3h C4h C5h C6h C7h C8h C9h CAh CBh CCh CDh CEh CFh
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
0001 0000 0001 0001 0001 0010 0001 0011 0001 0100 0001 0101 0001 0110 0001 0111 0001 1000 0001 1001 0001 1010 0001 1011 0001 1100 0001 1101 0001 1110 0001 1111
10h 11h 12h 13h 14h 15h 16h 17h 18h 19h 1Ah 1Bh 1Ch 1Dh 1Eh 1Fh
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
0101 0000 0101 0001 0101 0010 0101 0011 0101 0100 0101 0101 0101 0110 0101 0111 0101 1000 0101 1001 0101 1010 0101 1011 0101 1100 0101 1101 0101 1110 0101 1111
50h 51h 52h 53h 54h 55h 56h 57h 58h 59h 5Ah 5Bh 5Ch 5Dh 5Eh 5Fh
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
1001 0000 1001 0001 1001 0010 1001 0011 1001 0100 1001 0101 1001 0110 1001 0111 1001 1000 1001 1001 1001 1010 1001 1011 1001 1100 1001 1101 1001 1110 1001 1111
90h 91h 92h 93h 94h 95h 96h 97h 98h 99h 9Ah 9Bh 9Ch 9Dh 9Eh 9Fh
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
1101 0000 1101 0001 1101 0010 1101 0011 1101 0100 1101 0101 1101 0110 1101 0111 1101 1000 1101 1001 1101 1010 1101 1011 1101 1100 1101 1101 1101 1110 1101 1111
D0h D1h D2h D3h D4h D5h D6h D7h D8h D9h DAh DBh DCh DDh DEh DFh
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
0010 0000 0010 0001 0010 0010 0010 0011 0010 0100 0010 0101 0010 0110 0010 0111 0010 1000 0010 1001 0010 1010 0010 1011 0010 1100 0010 1101 0010 1110 0010 1111
20h 21h 22h 23h 24h 25h 26h 27h 28h 29h 2Ah 2Bh 2Ch 2Dh 2Eh 2Fh
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
0110 0000 0110 0001 0110 0010 0110 0011 0110 0100 0110 0101 0110 0110 0110 0111 0110 1000 0110 1001 0110 1010 0110 1011 0110 1100 0110 1101 0110 1110 0110 1111
60h 61h 62h 63h 64h 65h 66h 67h 68h 69h 6Ah 6Bh 6Ch 6Dh 6Eh 6Fh
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
1010 0000 1010 0001 1010 0010 1010 0011 1010 0100 1010 0101 1010 0110 1010 0111 1010 1000 1010 1001 1010 1010 1010 1011 1010 1100 1010 1101 1010 1110 1010 1111
A0h A1h A2h A3h A4h A5h A6h A7h A8h A9h AAh ABh ACh ADh AEh AFh
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
1110 0000 1110 0001 1110 0010 1110 0011 1110 0100 1110 0101 1110 0110 1110 0111 1110 1000 1110 1001 1110 1010 1110 1011 1110 1100 1110 1101 1110 1110 1110 1111
E0h E1h E2h E3h E4h E5h E6h E7h E8h E9h EAh EBh ECh EDh EEh EFh
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
0011 0000 0011 0001 0011 0010 0011 0011 0011 0100 0011 0101 0011 0110 0011 0111 0011 1000 0011 1001 0011 1010 0011 1011 0011 1100 0011 1101 0011 1110 0011 1111
30h 31h 32h 33h 34h 35h 36h 37h 38h 39h 3Ah 3Bh 3Ch 3Dh 3Eh 3Fh
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
0111 0000 0111 0001 0111 0010 0111 0011 0111 0100 0111 0101 0111 0110 0111 0111 0111 1000 0111 1001 0111 1010 0111 1011 0111 1100 0111 1101 0111 1110 0111 1111
70h 71h 72h 73h 74h 75h 76h 77h 78h 79h 7Ah 7Bh 7Ch 7Dh 7Eh 7Fh
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
1011 0000 1011 0001 1011 0010 1011 0011 1011 0100 1011 0101 1011 0110 1011 0111 1011 1000 1011 1001 1011 1010 1011 1011 1011 1100 1011 1101 1011 1110 1011 1111
B0h B1h B2h B3h B4h B5h B6h B7h B8h B9h BAh BBh BCh BDh BEh BFh
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
1111 0000 1111 0001 1111 0010 1111 0011 1111 0100 1111 0101 1111 0110 1111 0111 1111 1000 1111 1001 1111 1010 1111 1011 1111 1100 1111 1101 1111 1110 1111 1111
F0h F1h F2h F3h F4h F5h F6h F7h F8h F9h FAh FBh FCh FDh FEh FFh
Copyright ©2007 Global Knowledge Training LLC. All rights reserved.
Page 11
Some Ways To Use This Knowledge You might question the usefulness of what you just learned. Well, let us consider a few practical examples of how one might apply this knowledge. Case 1 – IP Addresses IP addresses are really 32 bit binary numbers. But we write them using what is called dotted-decimal notation. Consider this IP address: 10.1.1.5 In binary, that appears as follows: 00001010 00000001 00000001 00000101 The spaces are just for clarity. Notice that the leftmost eight bits has the 8 and 2 bits on – that’s the 10. Each of the next two groups of eight bits only have the 1 bit on – that is the 1s you see in the address. And the last group of eight bits has the 4 and 1 bits on – which is, of course, the 5. Do you see how this works? Each of those decimal numbers that appears in the dotted-decimal address converts to an 8 bit binary number. Collectively, the four groups of eight bits form the 32 bit IP address. Case 2 – Subnet Masks Subnet masks are also 32 bit binary numbers, also written in dotted-decimal notation. Here is an example: 255.255.255.240 In binary, that mask is as follows: 11111111 11111111 11111111 11110000 The value 255 decimal converts to 11111111 in binary. If you are in doubt, add 128+64+32+16+8+4+2+1; you get 255. Consider the 240. “Pay” out 240 in bin-o-bucks. That would be 128+64+32+16. Those are the bits on in that last group of eight bits; the others (8, 4, 2, and 1) are zero. Maybe it would be clearer to see it this way: Bin-o-Bucks 128 1 1
64 1 1
32 1 1
16 1 1
8 1 0
4 1 0
2 1 0
1 1 0
Decimal 255 240
Case 3 – Character Codes (e.g. ASCII) Imagine looking at an ASCII code chart like the partial one in Figure J. These codes are actually binary values that we use to represent each of the commonly used letters, digits, and special characters. What is the ASCII code for “f”?
Copyright ©2007 Global Knowledge Training LLC. All rights reserved.
Page 12
It is easy to spot – “f” is encoded as the hex value 66. Okay, but what is the binary code; that is not shown in the table. Hex Digit 6
8 0
Binary 4 2 1 1 1 0
Simply convert the hex 66 to binary. Each of the 6s translates to binary 0110. So your answer is 0110 0110.
Char a b c d e f g h i
Dec 96 97 98 99 100 101 102 103 104 105
Oct 0140 0141 0142 0143 0144 0145 0146 0147 0150 0151
Hex 0x60 0x61 0x62 0x63 0x64 0x65 0x66 0x67 0x68 0x69
Figure J. Conversion Table
Case 4 – Protocol Analysis You have captured an Ethernet frame traversing the network and have dumped it out. The length of the frame is sometimes encoded in the 13th and 14th bytes of the Ethernet header. See Figure K. 0000 0010 0020 0030
01 03 00 02
80 00 00 00
c2 00 80 0f
00 00 00 00
00 00 00 00
00 00 04 00
00 80 e2 00
04 00 de 00
e2 00 ff 00
de 04 f8 00
ff e2 80 00
ff de 08 00
00 ff 00 00
26 f8 00 00
42 00 14 02
42 00 00 00
........ ........ ........ ........
.....&BB ........ ........ ........
Figure K. Ethernet dump
The dump shows the hex value 0026 in that part of the header. What is that in decimal? 4096
256
16 2
1 6
Simple, two 16s plus six 1s, 38 bytes.
Conclusion You have learned that three systems of numbers are often encountered in IT-related studies. They are decimal, binary, and hexadecimal. People like decimal. Computers like binary. Neither likes hexadecimal – hex is just a great shorthand for binary. All of the number systems have three things in common: • Each has a “base” value • Each system has a limited number of “digits” to work with • They all rely upon “positional notation” to convey the significance of the digits within a given number Conversion between these systems is a common chore. You can do it manually by applying your knowledge of these number systems. Or, you might prefer to use one of the tools, like calculators or reference tables, to assist in this. Good luck working with these numbers in the future.
Copyright ©2007 Global Knowledge Training LLC. All rights reserved.
Page 13
Learn More Learn more about how you can improve productivity, enhance efficiency, and sharpen your competitive edge. Check out the following Global Knowledge courses: Network+ Boot Camp Understanding Networking Fundamentals TCP/IP Networking For more information or to register, visit www.globalknowledge..com or call 1-800-COURSES to speak with a sales representative. Our courses and enhanced, hands-on labs offer practical skills and tips that you can immediately put to use. Our expert instructors draw upon their experiences to help you understand key concepts and how to apply them to your specific work situation. Choose from our more than 700 courses, delivered through Classrooms, e-Learning, and On-site sessions, to meet your IT and management training needs.
About the Author George Mays has over 35 years’ experience in computing, data communications, and networking. His experience includes mainframe systems programmer, Fortune 500 DBA, management of systems programming, data communications, IT operations, engineering, software development, and networking. He is also the author and course director for Global Knowledge’s Network+ Boot Camp and has contributed to several hacking and security books. George holds various industry certifications including CISSP, CCNA, A+, Network+, Security+, INet+. Past certification: MCSE. He is an instructor in TCP/IP, Troubleshooting, Network Protocols, Network Fundamentals, A+, Security+ and CISSP. In addition to teaching for Global Knowledge, Mr. Mays also acts as a consultant in the fields of general networking and security.
*Bin-o-Bucks and Hex-a-Bucks are the intellectual property of G.W. Mays & Associates, Inc. of Helotes, Texas. All Rights Reserved.
Copyright ©2007 Global Knowledge Training LLC. All rights reserved.
Page 14