When designing IP networks and allocating addresses it is important to be able to convert binary (base 2) numbers into decimal (base 10) numbers and vice versa. While many calculators (including the software calculator in Microsoft Windows) have functions for doing this they may not always be available. The following information may help you to convert numbers to and from binary without other assistance.
Binary is a numbering system made up of two numbers or states. These are represented by the numbers zero (0) and one (1). Counting in binary start at zero and follows like this:
Binary | Decimal |
0 | 0 |
1 | 1 |
10 | 2 |
11 | 3 |
100 | 4 |
101 | 5 |
110 | 6 |
111 | 7 |
1000 | 8 |
Each 0 or 1 is called a bit. Eight bits is normally called a byte, or an octet in IP addressing. IP addresses are 32 bit numbers and are broken into 4 groups of 8 bits or 4 octets. Normally we write IP addresses using dotted decimal notation like this:
192.168.24.57
where each number is really an 8 bit binary number. If we were to convert this number to binary it would be:
11000000 10101000 00011000 00111001
To do this type of conversion lets first look at how to convert binary to decimal.
Each binary digit in a binary number represents a value just as a digit in a decimal number does. In decimal the following values apply to each digit:
Similarly for binary numbers the following values apply:
To convert a binary number to a decimal number you simply need to know the value of the digit's position and add up those values for every position that contains a one (1). Lets look at our example IP address 192.168.24.57 using a table:
Decimal |
192 | 168 | 24 | 57 | ||||||||||||||||||||||||||||
Binary | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 1 |
Position Values | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 7 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | 128 | 64> | 32 | 16 | 8 | 4 | 2 | 1 |
Calculation | 128+64 = 192 | 128+32+8 = 168 | 16+8 = 24 | 32+16+8+1 = 57 |
As you can see from the table, taking a binary number and assigning the values to each position with a one and then adding the values equals the decimal value of that binary number. All you need to remember is to create a table of 8 locations and fill in the values from right to left with the powers of 2 starting at 2 to the power of 0 (20). This gives you the series of 1,2,4,8,16,32,64,128.
To convert a decimal number to binary you do the reverse. Simply subtract the largest value from the number that is less or equal to the number and keep subtracting position values from the result until you get to zero. Then for every position value that was subtracted place a one (1) in the appropriate bit position. For example, to convert 168 into binary:
168 - 128 = 40 | 128 is the largest bit position value that is less than or equal to 168 |
40 - 32 = 8 | 32 is the largest bit position value that is less than or equal to 40 |
8 - 8 = 0 | 8 is the largest bit position value that is less than or equal to 8 |
Therefore you were able to subtract the numbers 128, 32 and 8. Placing ones (1) in the corresponding bit positions and zeros (0) in all other bit positions would give you:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 |
That is, 168 is 10101000 in binary.
about ePipe | products | solutions | support | information center | contact us
Copyright © 2002 ePipe Pty. Ltd. All rights reserved.