Networking / Beginners

Understanding Binary

Before you can understand the details of how IP addressing works, you need to understand how the binary numbering system works because binary is the basis of IP addressing.

Binary is a counting system that uses only two numerals: 0 and 1. In the decimal system (with which most people are accustomed), you use 10 numerals: 0-9. In an ordinary decimal number - such as 3,482 - the rightmost digit represents ones; the next digit to the left, tens; the next, hundreds; the next, thousands; and so on. These digits represent powers of ten: first 100 (which is 1); next, 101 (10); then 102 (100); then 103 (1,000); and so on.

In binary, you have only two numerals rather than ten, which is why binary numbers look somewhat monotonous, as in 110011, 101111, and 100001.

The positions in a binary number (called bits rather than digits) represent powers of two rather than powers of ten: 1, 2, 4, 8, 16, 32, and so on. To figure the decimal value of a binary number, you multiply each bit by its corresponding power of two and then add the results. The decimal value of binary 10111, for example, is calculated as follows:

  1 x 20 = 1 x 1  = 1
+ 1 x 21 = 1 x 2  = 2
+ 1 x 22 = 1 x 4  = 4
+ 0 x 23 = 0 x 8  = 0
+ 1 x 24 = 1 x 16 = 16
		    23

Fortunately, converting a number between binary and decimal is something a computer is good at - so good, in fact, that you're unlikely ever to need to do any conversions yourself. The point of learning binary is not to be able to look at a number such as 1110110110110 and say instantly, "Decimal 7,606!".

Instead, the point is to have a basic understanding of how computers store information and - most important - to understand how the binary counting system works, which describe in the following section.

Here are some of the more interesting characteristics of binary and how the system is similar to and differs from the decimal system:

  • In decimal, the number of decimal places allotted for a number determines how large the number can be. If you allot six digits, for example, the largest number possible is 999,999. Because 0 is itself a number, however, a six-digit number can have any of 1 million different values.
    Similarly, the number of bits allotted for a binary number determines how large that number can be. If you allot eight bits, the largest value that number can store is 11111111, which happens to be 255 in decimal.
  • To quickly figure how many different values you can store in a binary number of a given length, use the number of bits as an exponent of two. An eight-bit binary number, for example, can hold 28 values. Because 28 is 256, an eight-bit number can have any of 256 different values. This is why a byte - eight bits - can have 256 different values.
  • This "powers of two" thing is why computers don't use nice, even, round numbers in measuring such values as memory or disk space. A value of 1K, for example, is not an even 1,000 bytes: It's actually 1,024 bytes because 1,024 is 210. Similarly, 1MB is not an even 1,000,000 bytes but instead 1,048,576 bytes, which happens to be 220.
    One basic test of computer nerddom is knowing your powers of two because they play such an important role in binary numbers. Just for the fun of it, but not because you really need to know, Table-1 lists the powers of two up to 32.
    Table-1 also shows the common shorthand notation for various powers of two. The abbreviation K represents 210 (1,024). The M in MB stands for 220, or 1,024K, and the G in GB represents 230, which is 1,024MB. These shorthand notations don't have anything to do with TCP/IP, but they're commonly used for measuring computer disk and memory capacities.
Table-1 Powers of Two
PowerBytesKilobytesPowerBytesK, MB, or GB
212217131,072128K
224218262,144256K
238219524,288512K
24162201,048,5761MB
25322212,097,1522MB
26642224,194,3044MB
271282238,388,6088MB
2825622416,777,21616MB
2951222533,554,43232MB
2101,0241K22667,108,86464MB
2112,0482K227134,217,728128MB
2124,0964K228268,435,456256MB
2138,1928K229536,870,912512MB
21416,38416K2301,073,741,8241GB
21532,76832K2312,147,483,6482GB
21665,53664K2324,294,967,2964GB

Doing the logic thing

One of the great things about binary is that it's very efficient at handling special operations: namely, logical operations. Four basic logical operations exist although additional operations are derived from the basic four operations. Three of the operations - AND, OR, and XOR - compare two binary digits (bits). The fourth (NOT) works on just a single bit.

The following list summarizes the basic logical operations:

  • AND: An AND operation compares two binary values. If both values are 1, the result of the AND operation is 1. If one or both of the values are 0, the result is 0.
  • OR: An OR operation compares two binary values. If at least one of the values is 1, the result of the OR operation is 1. If both values are 0, the result is 0.
  • XOR: An XOR operation compares two binary values. If exactly one of them is 1, the result is 1. If both values are 0 or if both values are 1, the result is 0.
  • NOT: The NOT operation doesn't compare two values. Instead, it simply changes the value of a single binary value. If the original value is 1, NOT returns 0. If the original value is 0, NOT returns 1.
Table-2 summarizes how AND, OR, and XOR work. Table-2 Logical Operations for Binary Values

First Value 	Second Value 	AND 	OR 	XOR
0 		0 		0 	0 	0
0 		1		0 	1 	1
1 		0 		0 	1 	1
1 		1 		1 	1 	0

Logical operations are applied to binary numbers that have more than one binary digit by applying the operation one bit at a time. The easiest way to do this manually is to line the two binary numbers on top of one another and then write the result of the operation beneath each binary digit. The following example shows how you would calculate 10010100 AND 11011101:

    10010100
AND 11011101
    10010100

As you can see, the result is 10010100.

Working with the binary Windows Calculator

The Calculator program that comes with all versions of Windows has a special Scientific mode that many users don't know about. When you flip the Calculator into this mode, you can do instant binary and decimal conversions, which can occasionally come in handy when you're working with IP addresses.

To use the Windows Calculator in Scientific mode, launch the Calculator by choosing Start → All Programs → Accessories → Calculator. Then, choose the View → Scientific command from the Calculator menu. The Calculator changes to a fancy scientific model.

You can select the Bin and Dec radio buttons to convert values between decimal and binary. For example, to find the binary equivalent of decimal 155, enter 155 and then select the Bin radio button. The value in the display changes to 10011011.

Here are a few other things to note about the Scientific mode of the Calculator:

  • Although you can convert decimal values to binary values with the scientific Calculator, the Calculator can't handle the dotted-decimal IP address format that's described later in this tutorial. To convert a dotted-decimal address to binary, just convert each octet separately. For example, to convert 172.65.48.120 to binary, first convert 172; then convert 65; then convert 48; and finally, convert 120.
  • The scientific Calculator has several features that are designed specifically for binary calculations, such as AND, XOR, NOT, NOR, and so on.
  • The scientific Calculator can also handle hexadecimal conversions. Hexadecimal doesn't come into play when dealing with IP addresses, but it is used for other types of binary numbers, so this feature sometimes proves to be useful.
  • Windows 7 does the scientific Calculator one step better by providing a Programmer mode which has even more features for working with binary numbers.
[Contents] [Next]