Saturday, March 13, 2010

Decimal and binary conversion

Decimal and binary conversion
9.2.2 There are several ways to convert decimal numbers to binary numbers. This page will describe one method.


The student may find other methods easier. It is a matter of personal preference.

When converting a decimal number to binary, the biggest power of two that will fit into the decimal number must be determined. If this process is designed to be working with computers, the most logical place to start is with the largest values that will fit into a byte or two bytes. As mentioned earlier, the most common grouping of bits is eight, which make up one byte. However, sometimes the largest value that can be held in one byte is not large enough for the values needed. To accommodate this, bytes are combined. Instead of having two eight-bit numbers, one 16-bit number is created. Instead of three eight-bit numbers, one 24-bit number is created. The same rules apply as they did for eight-bit numbers. Multiply the previous position value by two to get the present column value.

Since working with computers often is referenced by bytes it is easiest to start with byte boundaries and calculate from there. Start by calculating a couple of examples, the first being 6,783. Since this number is greater than 255, the largest value possible in a single byte, two bytes will be used. Start calculating from 215. The binary equivalent of 6,783 is 00011010 01111111.

The second example is 104. Since this number is less than 255, it can be represented by one byte. The binary equivalent of 104 is 01101000.

This method works for any decimal number. Consider the decimal number one million. Since one million is greater than the largest value that can be held in two bytes, 65535, at least three bytes will be needed. By multiplying by two until 24 bits, three bytes, is reached, the value will be 8,388,608. This means that the largest value that 24 bits can hold is 16,777,215. So starting at the 24-bit, follow the process until zero is reached. Continuing with the procedure described, it is determined that the decimal number one million is equal to the binary number 00001111 01000010 01000000.

Figure includes some decimal to binary conversion exercises.

Binary to decimal conversion is just the opposite. Simply place the binary in the table and if there is a one in a column position add that value into the total. Convert 00000100 00011101 to decimal. The answer is 1053.

Figure includes some binary to decimal conversion exercises.

The next page will discuss IPv4 addressing.

No comments:

Post a Comment