Freigeben über


Converting binary to decimal

Applies To: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1, Windows Server 2003 with SP2

Converting binary to decimal

Because all IP addresses and subnet mask values are composed of a standard-length 32-bit data field, they are viewed and interpreted by computers as a single binary numeric string, such as:

10000011 01101011 00000111 00011011

To communicate IP addresses simply and enter them in configurations quickly, you can use dotted decimal notation to convert IP address numbers from binary format.

With dotted decimal notation, each 32-bit address number is viewed as four distinct groupings of 8 bits. Each of the four groupings of 8 consecutive bits is referred to as an octet.

The first octet uses the first 8 bits (bit places 1-8), the second octet uses the next 8 bits (bit places 9-16), followed by the third octet (bit places 17-24) and fourth octet (bit places 25-32). Periods are used to separate the four octets that are described as separate decimal number values in the IP address.

The following table shows the scientific notation for each bit place in an individual octet and the equivalent decimal value.

Equivalent decimal values for bit places in a single IP address octet

Octet 1st bit 2nd bit 3rd bit 4th bit 5th bit 6th bit 7th bit 8th bit

Scientific notation

27

26

25

24

23

22

21

20

Decimal notation

128

64

32

16

8

4

2

1

For example, if the first bit place is filled with a bit value of 1, the equivalent decimal value is 128. Where the bit value is 0, the equivalent decimal value is 0 as well.

If all the bit places in an octet are filled with ones (1), the highest equivalent decimal value is 255. If all the bit places are filled with zeroes (0), the lowest equivalent decimal value is 0.

To see how each octet in an IP address is converted from an 8-digit binary number to an equivalent decimal number from 0 through 255, a brief example follows.

The following binary string shows the first octet in an IP address:

10000011

In this 8-digit binary number the first, seventh, and eighth bit places are filled with ones. All other bit places are filled with zeroes. By using the previous table as a reference, you can perform simple addition of each bit place's decimal equivalent value to find the decimal sum for this octet string, as follows:

1st bit (128) + 7th bit (2) + 8th bit (1) = octet total (131)

Because the sum is 131, the first octet of the example IP address is 131. After using this method on the other octets, the final result of the conversion is the dotted decimal equivalent: 131.107.7.27.