Using DataRelate - Understanding Decimal, Binary and Hexadecimal Notation

Decimal 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). 

Go to the 'Base Convert' panel and type the number '42' in the Decimal box. The Binary box instantly shows '101010' (the Hex box also shows '2A', but more about that later).

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:

Operation Hexadecimal Binary Decimal
None 2A 101010 42
Right shift by 1 15 010101 21
Right shift by 2 A 001010 10

Operation Hexadecimal Binary Decimal
None 2A 00101010 42
Left shift by 1 54 01010100 84
Left shift by 2 A8 10101000 168
 
Notice that pressing the 'Right Shift' arrow once divides our number by 2, and pressing the 'Right Shift' arrow twice almost produces a number 4 times smaller than the original number (the reason it is not exactly 4 times smaller is due to the fact that we are dealing with Integers - fractions cannot be saved in these types of numbers). Before performing a Left shift, first prefix a couple of zeroes to the Binary number representing 42 (displaying it as an '8 bit' sequence), so that when you shift Left, there is no bit overflow. Then notice that pressing the 'Left Shift' arrow once multiplies our number by 2, and pressing the 'Left Shift' arrow twice produces a number 4 times greater than the original number. A three-bit shift in either direction would multiply/divide our number by 8. So, as a rule, assuming no bit overflow:

A n bit left shift multiplies by 2n. A n bit right shift divides by 2n.

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:

Example 1. Show -35 in Binary using 2's complement.

i. Type in '35' in the Decimal box in the Base Convert panel. The Binary equivalent is displayed as '100011'

ii. Prefiex a couple of zeroes to the Binary number to show it as an 8-bit sequence: '00100011'

iii. Press 'Invert' - this gives us '11011100'

iv. Add 1 to the inverted sequence - which gives us '11011101'

So, 11011101 is our 2's complement representation of -35. 

 
Example 2. You are given the sequence 11111101, and told that this represents a negative number. Determine what that number is.

i. Type in the sequence '11111101' in the Binary box in the Base Convert panel.

ii. Press 'Invert' - this gives us '00000010'

iii. Add 1 to the inverted sequence - which gives us '00000011'

iv. The Decimal box shows the Decimal equivalent of that Binary sequence to be the number '3'

So, 11111101 represents the number -3.

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:

Decimal Hexadecimal Binary
0 0000
0001
0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111

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 1010(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!

TOP

 
Send mail to jimsingh@bigpond.com with questions or comments about this web site.
Copyright © 2003 Measurement and Conversion Software
Last modified: September 16, 2003