Number Systems Decoded Binary, Decimal, and Hexadecimal
Total Page:16
File Type:pdf, Size:1020Kb
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 sys- tems 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 num- ber 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 hexa- decimal 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 trip- pingly 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, comput- ers love it. Hexadecimal was invented to intimidate those who are new to information technologies. It is the number sys- tem 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 cumber- some 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 A 10 These symbols are letters of the alphabet. You know that; I know that. However, in hexadecimal numbers, they are digits, B 11 perfectly good digits. C 12 D 13 Someone might point out to you that there are 3 windows in the classroom. The digit 3 conjures up something in your brain – E 14 the notion of the quantity 3. In like manner, I could note that F 15 there are B desks in the classroom. That should make you think of the quantity 11, hence 11 desks are present. Figure B. Hex Digit Values in Decimal Copyright ©2007 Global Knowledge Training LLC. All rights reserved. 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 interpret- 1000s 100s 8s 1s ed differently than the one appearing two positions to the 1 5 8 5 left. That is to say that the position in which a digit appears has everything to do with the significance or 1000 500 80 5 = 1585 weight that we attach to it. In this case the rightmost 5 implies 5 ones and that to the left implies 5 hundreds. 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 sym- bol 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 8s 4s 2s 1s place, as it was in the decimal example. (See Figure D.) 1 0 0 1 But as we progress to the left, each position carries a weight that is 2 times the one on its right. Thus we 8 0 0 1 = 9 observe the ones place, twos place, fours place, eights Figure D. Binary Notation place, and so on. 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 quan- tity 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 differ- ence does not matter. Second, as noted previously, some 256 32 10 = 298 people cringe seeing letters of the alphabet in numbers. Put your confusion aside. Just as the regular-old-every- Figure E. Hex Notation day 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 men- tal gymnastics one realizes the A ones means 10 (decimal) ones to mere mortals.