X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=doc%2Fbin_dec_hex.txt;h=334c425e1d229b5c1491bbc1014cfe85173442ed;hb=d9822df7ed5e8122cf3a62e4e99678e94007f504;hp=3fe4075b93ba827eebef93b3816bf2a0acf03244;hpb=07320f320eac039c03ca18bfb5eeea5803701dfe;p=pkg-rrdtool.git diff --git a/doc/bin_dec_hex.txt b/doc/bin_dec_hex.txt index 3fe4075..334c425 100644 --- a/doc/bin_dec_hex.txt +++ b/doc/bin_dec_hex.txt @@ -6,8 +6,8 @@ NNAAMMEE bin_dec_hex - How to use binary, decimal, and hexadecimal notation. DDEESSCCRRIIPPTTIIOONN - Most people use the decimal numbering system. This system uses ten sym- - bols to represent numbers. When those ten symbols are used up, they + Most people use the decimal numbering system. This system uses ten + symbols to represent numbers. When those ten symbols are used up, they start all over again and increment the position to the left. The digit 0 is only shown if it is the only symbol in the sequence, or if it is not the first one. @@ -31,9 +31,9 @@ DDEESSCCRRIIPPTTIIOONN and so on. - Each time the digit nine is incremented, it is reset to 0 and the posi- - tion before (to the left) is incremented (from 0 to 1). Then number 9 - can be seen as "00009" and when we should increment 9, we reset it to + Each time the digit nine is incremented, it is reset to 0 and the + position before (to the left) is incremented (from 0 to 1). Then number + 9 can be seen as "00009" and when we should increment 9, we reset it to zero and increment the digit just before the 9 so the number becomes "00010". Leading zeros we don't write except if it is the only digit (number 0). And of course, we write zeros if they occur anywhere inside @@ -66,39 +66,39 @@ DDEESSCCRRIIPPTTIIOONN If you count the number of rows, you'll see that these are again 14 different numbers. The numbers are the same and mean the same as in the first list, we just used a different representation. This means that - you have to know the representation used, or as it is called the num- - bering system or base. Normally, if we do not explicitly specify the - numbering system used, we implicitly use the decimal system. If we want - to use any other numbering system, we'll have to make that clear. There - are a few widely adopted methods to do so. One common form is to write - 1010(2) which means that you wrote down a number in its binary repre- - sentation. It is the number ten. If you would write 1010 without speci- - fying the base, the number is interpreted as one thousand and ten using - base 10. - - In books, another form is common. It uses subscripts (little charac- - ters, more or less in between two rows). You can leave out the paren- - theses in that case and write down the number in normal characters fol- - lowed by a little two just behind it. + you have to know the representation used, or as it is called the + numbering system or base. Normally, if we do not explicitly specify + the numbering system used, we implicitly use the decimal system. If we + want to use any other numbering system, we'll have to make that clear. + There are a few widely adopted methods to do so. One common form is to + write 1010(2) which means that you wrote down a number in its binary + representation. It is the number ten. If you would write 1010 without + specifying the base, the number is interpreted as one thousand and ten + using base 10. + + In books, another form is common. It uses subscripts (little + characters, more or less in between two rows). You can leave out the + parentheses in that case and write down the number in normal characters + followed by a little two just behind it. As the numbering system used is also called the base, we talk of the number 1100 base 2, the number 12 base 10. - Within the binary system, it is common to write leading zeros. The num- - bers are written down in series of four, eight or sixteen depending on - the context. + Within the binary system, it is common to write leading zeros. The + numbers are written down in series of four, eight or sixteen depending + on the context. - We can use the binary form when talking to computers (...program- - ming...), but the numbers will have large representations. The number - 65'535 (often in the decimal system a ' is used to separate blocks of - three digits for readability) would be written down as + We can use the binary form when talking to computers + (...programming...), but the numbers will have large representations. + The number 65'535 (often in the decimal system a ' is used to separate + blocks of three digits for readability) would be written down as 1111111111111111(2) which is 16 times the digit 1. This is difficult and prone to errors. Therefore, we usually would use another base, called hexadecimal. It uses 16 different symbols. First the symbols - from the decimal system are used, thereafter we continue with alpha- - betic characters. We get 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E - and F. This system is chosen because the hexadecimal form can be con- - verted into the binary system very easily (and back). + from the decimal system are used, thereafter we continue with + alphabetic characters. We get 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, + E and F. This system is chosen because the hexadecimal form can be + converted into the binary system very easily (and back). There is yet another system in use, called the octal system. This was more common in the old days, but is not used very often anymore. As you @@ -137,10 +137,11 @@ DDEESSCCRRIIPPTTIIOONN Most computers used nowadays are using bytes of eight bits. This means that they store eight bits at a time. You can see why the octal system - is not the most practical for that: You'd need three digits to repre- - sent the eight bits and this means that you'd have to use one complete - digit to represent only two bits (2+3+3=8). This is a waste. For hex- - adecimal digits, you need only two digits which are used completely: + is not the most practical for that: You'd need three digits to + represent the eight bits and this means that you'd have to use one + complete digit to represent only two bits (2+3+3=8). This is a waste. + For hexadecimal digits, you need only two digits which are used + completely: (2) (8) (10) (16) 11111111 377 255 FF @@ -159,8 +160,8 @@ DDEESSCCRRIIPPTTIIOONN for HTML. It is common to assume that if a number starts with a zero, it is octal. It does not matter what is used as long as you know what it is. I will use "0x" for hexadecimal, "%" for binary and "0" for - octal. The following numbers are all the same, just their represenata- - tion (base) is different: 021 0x11 17 %00010001 + octal. The following numbers are all the same, just their + representation (base) is different: 021 0x11 17 %00010001 To do arithmetics and conversions you need to understand one more thing. It is something you already know but perhaps you do not "see" @@ -258,7 +259,7 @@ DDEESSCCRRIIPPTTIIOONN get 0xA04?. Subtract 64 from 69 (69 - 4*16) and the last digit is 5 --> 0xA045. - The other method builds ub the number from the right. Let's try 41'029 + The other method builds up the number from the right. Let's try 41'029 again. Divide by 16 and do not use fractions (only whole numbers). 41'029 / 16 is 2'564 with a remainder of 5. Write down 5. @@ -269,9 +270,9 @@ DDEESSCCRRIIPPTTIIOONN Which method to use is up to you. Use whatever works for you. I use them both without being able to tell what method I use in each case, it just depends on the number, I think. Fact is, some numbers will occur - frequently while programming. If the number is close to one I am famil- - iar with, then I will use the first method (like 32'770 which is into - 32'768 + 2 and I just know that it is 0x8000 + 0x2 = 0x8002). + frequently while programming. If the number is close to one I am + familiar with, then I will use the first method (like 32'770 which is + into 32'768 + 2 and I just know that it is 0x8000 + 0x2 = 0x8002). For binary the same approach can be used. The base is 2 and not 16, and the number of positions will grow rapidly. Using the second method has @@ -348,18 +349,19 @@ DDEESSCCRRIIPPTTIIOONN For low values, try to do the calculations yourself, then check them with a calculator. The more you do the calculations yourself, the more - you'll find that you didn't make mistakes. In the end, you'll do cal- - culi in other bases as easily as you do them in decimal. + you'll find that you didn't make mistakes. In the end, you'll do + calculi in other bases as easily as you do them in decimal. When the numbers get bigger, you'll have to realize that a computer is - not called a computer just to have a nice name. There are many differ- - ent calculators available, use them. For Unix you could use "bc" which - is short for Binary Calculator. It calculates not only in decimal, but - in all bases you'll ever want to use (among them Binary). + not called a computer just to have a nice name. There are many + different calculators available, use them. For Unix you could use "bc" + which is short for Binary Calculator. It calculates not only in + decimal, but in all bases you'll ever want to use (among them Binary). - For people on Windows: Start the calculator (start->programs->acces- - sories->calculator) and if necessary click view->scientific. You now - have a scientific calculator and can compute in binary or hexadecimal. + For people on Windows: Start the calculator + (start->programs->accessories->calculator) and if necessary click + view->scientific. You now have a scientific calculator and can compute + in binary or hexadecimal. AAUUTTHHOORR I hope you enjoyed the examples and their descriptions. If you do, help @@ -367,8 +369,8 @@ AAUUTTHHOORR basic questions. They will not only get their answer, but at the same time learn a whole lot more. - Alex van den Bogaerdt + Alex van den Bogaerdt -1.3.0 2008-03-15 BIN_DEC_HEX(1) +1.4.8 2013-05-23 BIN_DEC_HEX(1)