|
|
|
|
Using DataRelate - Understanding Decimal, Binary and Hexadecimal NotationDecimal Notation: We're all familiar with the decimal (base 10) system. We use it likely because we've got 10 fingers. To represent a number as base 10, you multiply the rightmost digit by 100, the next digit to the left by 101, and so on. Each digit to the left has a multiplier that is 10 times the previous digit thus: 14310 = 1*100 + 4*10 + 3*1 = 1*102 + 4*101 + 3*100 The subscript 10 indicates a decimal number. To multiply a number by 10 you can simply shift it to the left by one digit, and fill in the rightmost digit with a 0 (moving the decimal place to the right by one). To divide a number by 10, simply shift the number to the right by one digit (moving the decimal place to the left by one). Binary Notation: The number system based on ones and zeroes is called the binary system - since there are only two possible digits. Computers deal with nothing more than ones and zeroes - numbers are represented by only two voltage levels which can represent a one or a zero. (By the way, ones and zeroes don't always have to represent numbers. Often a one is used to represent the boolean value True and zero is used to represent the boolean value False). Binary representations can be understood in the same way as their decimal counterparts. For example: 4210 = 1*32 + 0*16 + 1*8 + 0*4 + 1*2 + 0*1 or 4210 = 1* 25 + 0* 24 + 1* 23 + 0* 22 + 1* 21 + 0* 20 or 4210 = 101010 2 The subscript 2 indicates a binary number. Each digit in a binary number is called a bit. The number 101010 is represented by 6 bits. Any number can be represented this way, by finding all of the powers of 2 that add up to the number in question (in this case 25, 23 and 21).
Shift and Rotate buttons: The Shift and Rotate operations are similar to each other in that in these two so called 'bitwise' operations, the position of the bits is moved but the order of bits is preserved. The only difference between the operations is what happens to the bits that are shifted out of the sequence. A Rotate command puts the bit that is pushed off, back into the sequence in the place that is on the opposite end of the sequence. A Shift operation simply gets rid of the end bit and places a 0 on the opposite end (note however, that in some processor architectures, a 1 or random bit is placed on the opposite end). As can be seen from the arrows, Shift and Rotate can be performed in either the right or left directions, and for any number of bits. Now we'll shift the bits in both directions:
Invert button: The Invert operation changes each bit in a sequence to its opposite ie where there is a '1', it is changed to '0', and where there is a '0', it is changed to '1'. The Invert operation is used in a procedure called '2's complement' to represent negative numbers in Binary. Note that although many methods have been proposed for showing negative numbers in Binary, the method most commonly used in our computers today is 2's complement. Here's how to do it:
Hexadecimal Notation: It is awkward for us humans to deal with reading and writing Binary sequences - since the sequences can become very long very quickly, and the best of us would be hard pressed to remember all the individual bits in their correct order. A few different ways have been developed to make the handling of binary data easier for us. The most common is hexadecimal, in which 4 bits are represented by a single digit - it is far more convenient to handle groups of bits, rather than individual bits. A problem appears though - 4 bits gives 16 possible combinations, and there are only 10 unique decimal digits: 0 to 9. This is solved by using the first 6 letters of the alphabet (A to F) as numbers. The following table shows the relationship between decimal, hexadecimal and binary:
Using hexadecimal makes it very easy indeed to convert back and forth from binary because each hexadecimal digit corresponds to exactly 4 bits. For example, the table tells us immediately that 2A16 = 0010 10102 (or 101010 if we drop the leading zeroes). Now, if only we had 16 fingers, we wouldn't need the unwieldy decimal system, which is not nearly as suited to the task of representing binary as hexadecimal! |
Send mail to jimsingh@bigpond.com with
questions or comments about this web site.
|