Tài liệu Number Systems Decoded Binary, Decimal, and Hexadecimal pdf

14 372 0
Tài liệu Number Systems Decoded Binary, Decimal, and Hexadecimal pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Number Systems Decoded Binary, Decimal, and Hexadecimal 1-800-COURSES www.globalknowledge.com Expert Reference Series of White Papers 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 George Mays, CISSP, CCNA, A+, Security+, Network+ Number Systems Decoded Binary, Decimal, and Hexadecimal Copyright ©2007 Global Knowledge T raining LLC. All rights reserved. Page 2 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 . T hese symbols simply represent quantities ,as follows: 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. T he 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 T raining LLC. All rights reserved. Page 3 Name Base Digits Decimal 10 0, 1, 9 Binary 2 0, 1 Hexadecimal 16 0, 9, A, F He xidecimal Digit Decimal V alue A 10 B 11 C 12 D 13 E 14 F 15 Figure B. Hex Digit Values in Decimal 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- ed 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. 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 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. T hus we observe the ones place, twos place, fours place, eights 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. T hat’ 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 T raining LLC. All rights reserved. Page 4 1000s 100s 8s 1s 1 5 8 5 1000 500 80 5 = 1585 8s 4s 2s 1s 1 0 0 1 8 0 0 1 = 9 Figure D. Binary Notation Figure C. Positional Notation A few observations are in order before proceeding. First, some people seem to think that there is some difference between a lower case “a” and an upper case “A.” There is not. You will see both cases regularly and the differ- ence does not matter. Second, as noted previously, some people cringe seeing letters of the alphabet in numbers. Put your confusion aside. Just as the regular-old-every- 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 v alue 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. 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 deci- mal 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 clari- fication provided to you. T he 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 101 10 then you are dealing with 101 base 10, decimal. The value 101 2 means that this is a binary (base 2) value. And, as you would expect, 101 16 implies a hexadecimal (base 16) value. Copyright ©2007 Global Knowledge T raining LLC. All rights reserved. Page 5 4096s 256s 16s 1s 1 2 A 256 32 10 = 298 Figure E. Hex Notation 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 8 4 2 1 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 8 4 2 1 10010 The binary value 10010 represents the decimal value 18. Easy. Try it again by converting the value 37 10 to bin- o-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 16 8 4 2 1 1 00101 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 4 2 1 1100 And 8 + 4 is 12. So a binary 1100 is the representation for a decimal 12. Copyright ©2007 Global Knowledge T raining LLC. All rights reserved. Page 6 T ry 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 Your result should look like this: 128 64 32 16 8 4 2 1 1001010 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 35 10 dollars, that would call for the use of two 16s and three 1s. 4096 256 16 1 2 3 So the value 23 is the hex representation of the decimal value 35. Try your hand at this. You need to pay out 25 10 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 T raining LLC. All rights reserved. Page 7 N ow, let’s say that you are asked to convert 54 1 6 t o base 10. Plug 54 into your cheat-sheet. You get: 4096 256 16 1 54 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: 1E 16 = ? 10 . Here is your cheat sheet: 4096 256 16 1 1E 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 14 10 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 Binary Hex Binary Hex Binary Hex Binary 0 0000 4 0100 8 1000 C 1100 1 0001 5 0101 9 1001 D 1101 2 0010 6 0110 A 1010 E 1110 3 0011 7 0111 B 1011 F 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 6 16 look like in binary? 8 4 2 1 0 110 Notice the 4 and the 2 bit (binary digit) positions are set to 1. T he other positions are 0. One 4 plus one 2 equals 6. Or how about the 9 16 table entry? In binary it looks lik e: 8 4 2 1 1 001 That’s one 8 plus one 1, or 9. Now that you know how this substitution table w as constructed, let’ s convert a sample hex v alue, 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 T raining LLC. All rights reserved. Page 8 H ex value to be converted: B 8 Substitute 1011 for hex B: 1011 8 Substitute 1000 for hex 8: 1011 1000 Try another example. 4F1 16 = ? 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: 4F1 Substitute 0100 for hex 4: 0100 F 1 Substitute 1111 for hex F: 0100 1111 1 Substitute 0001 for hex 1: 0100 1111 0001 Binary to Hexadecimal Converting a binary v alue 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: 10110110 Identify groups of four bits: 1011 0110 Substitute hex 6 for 0110: 6 Substitute hex B for 1011: B6 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: 1010110110 Identify groups of four bits: 10 1011 0110 Pad the left with zero bits: 0010 1011 0110 Substitute hex 6 for 0110: 6 Substitute hex B for 1011: 2 B 6 Substitute hex 2 for 0010: 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 . Y ou 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. Copyright ©2007 Global Knowledge T raining LLC. All rights reserved. Page 9 Figur e F. Calculator T oward 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. 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 sys - tems. If you are curious, Oct stands for the octal, or base 8, number system. 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 con- verts any number that you enter here to each of the number sys- tems 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 cor- rect the Number Converter if it guesses wrong. 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 T raining LLC. All rights reserved. Page 10 F igure G. Hex Calculator Figure H. Hex Conversion Figure I. Number Converter 2.0 [...]... 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... 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,... “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... 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... 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,. .. 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,... 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... 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... 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... 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 . appreciation of numbers. Several systems of numbers are commonly used in computing circles. These are the decimal, binary, and hexa- decimal number systems . These. Network+ Number Systems Decoded Binary, Decimal, and Hexadecimal Copyright ©2007 Global Knowledge T raining LLC. All rights reserved. Page 2 Figure A Number

Ngày đăng: 24/01/2014, 10:20

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan