## 4.4 Network Math and Metric Units

Computers can only understand and use data that is in this two-state or binary format. The ones and zeros are used to represent the two possible states of an electronic component in a computer. 1 is represented by an ON state, and 0 is represented by an OFF state. They are referred to as binary digits or bits. The word bit is a shortening of the words "Binary digIT".

Bit is basic unit of (digital) information.

A binary 0 might be represented by 0 volts and binary 1 might be represented by +5 volts. Volt [V] is the standard unit of measurement for electrical potential. It defines the "force" of electricity.

Bits and binary numbers are natural to computers and other digital devices. Humans use the decimal number system, which is relatively simple when compared to the long series of ones and zeros used by computers. So the binary numbers need to be converted to decimal numbers.

Byte is a grouping of eight bits. In a computer, one byte represents a single addressable storage location.

Base-10 Number System (Decimal Number System) - The easiest way to understand bits is to compare them to something we know: digits. A digit is a single place that can hold numerical values between 0 and 9. Digits are normally combined together in groups to create larger numbers. For example, 7 214 has four digits. It is understood that in the number 7 214, the 4 is filling the "1s place" while the 1 is filling the 10s place, the 2 is filling the 100s place and the 7 is filling the 1 000s place. We could express things this way if we wanted to be explicit:

(7 * 1000) + (2 * 100) + (1 * 10) + (4 * 1) = 7000 + 200 + 10 + 4 = 7214

Another way to express it would be to use powers of 10. So:

(7 * 103) + (2 * 102) + (1 * 101) + (4 * 100) = 7000 + 200 + 10 + 4 = 7214

What we can see from this expression is that each digit is a placeholder for the next higher power of 10, starting in the first digit with 10 raised to the power of zero.

There is nothing that forces us to have 10 different values in a digit. Our base-10 number system likely grew up because we have 10 fingers, but if we happened to evolve to have five fingers instead, we would probably have a base-5 number system. We can have base-n number systems, where n is number of digits used. In fact, there are lots of good reasons to use different bases in different situations.

Base-2 Number System (Binary Number System) – A binary number is composed of only ones and zeros, for example: 1101. How do we figure out what the value of the binary number 1101 is? We do it in the same way we did it above for 7 214 but we use a base of 2 instead of a base of 10. So:

1101(2) = (1 * 23) + (1 * 22) + (0 * 21) + (1 * 20) = 8 + 4 + 0 + 1 = 13(10)

We can see that in binary numbers, each bit holds the value of increasing powers of 2. That makes counting in binary pretty easy. Starting at zero and going through 16, counting in decimal and binary looks as shown in Table 1:

Table 1: Binary Counting
Decimal Number Binary Number
0 0
1 1
2 10
3 11
4 100
5 101
6 110
7 111
8 1000
9 1001
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111
16 10000
etc.

When we look at sequence shown in Table 1, 0 and 1 are the same for decimal and binary number systems. At the number 2, you see carrying first take place in the binary system. If a bit is 1 and you add 1 to it the bit becomes 0 and the next bit becomes 1. In the transition from 15 to 16 this effect rolls over through 4 bits, turning 1111 into 10000.

With one byte (8 bits), we can represent 256 values ranging from 0 to 255, as shown in Table 2:

Table 2: 256 values with 8 bits
Decimal Number 8-bit Binary Number
0 00000000
1 00000001
2 00000010
...
253 11111101
254 11111110
255 11111111

Generally, with n bits we can represent 2n values ranging from 0 to 2n-1.

Base-16 Number System (Hexadecimal Number System or Hex) - A number system with a base of 16. Written using the symbols 0–9 and A–F, or a–f. Its primary purpose is to represent the binary code in a format easier for humans to read, and acts as a form of shorthand, in which one hexadecimal digit stands in place of four bits. For example, the decimal number 157, whose binary representation is 10011101 is 9D in hexadecimal. (9(16) =1001(2), D(16) = 1101(2))

Logical Operations – Now we will provide a brief explanation of the common logical operations AND, OR, NOT and XOR (eXclusive OR). Logical operations are performed between two bits (except for NOT operation). Bits can be either 1 or 0, and these operations are essential to performing network math operations.

In the "truth tables" below the p and q are input bits.

AND operation - The logical AND operation compares 2 bits and if they are both 1, then the result is 1, otherwise, the result is 0.

Table 3: Logical AND operation
p q p AND q
0 0 0
0 1 0
1 0 0
1 1 1

OR operation - The logical OR operation compares 2 bits and if either or both bits are 1, then the result is 1, otherwise, the result is 0.

Table 4: Logical OR operation
p q p OR q
0 0 0
0 1 1
1 0 1
1 1 1

NOT operation - The logical NOT operation simply changes the value of a single bit. If it is a 1, the result is 0; if it is a 0, the result is 1. This operation is different in that instead of comparing two bits, it is acting on a single bit.

Table 5: Logical NOT operation
p NOT p
0 1
1 0

XOR operation - The logical XOR (eXclusive OR) operation compares 2 bits and if exactly one of them is 1 (i.e. if they are different values), then the result is 1; otherwise (if the bits are the same) the result is 0

Table 6: Logical XOR operation
p q p XOR q
0 0 0
0 1 1
1 0 1
1 1 0

Metric units – For measuring memory, disk, file, and database sizes, in practice, the units have slightly different meanings then in SI system of units. Prefix kilo means 210 (1024) rather than 103 (1000) because memories are always a power of two. Thus, a 1 KB memory contains 1024 bytes, not 1000 bytes. Similarly, a 1 MB memory contains 220 (1 048 576) bytes, a 1 GB memory contains 230 (1 073 741 824) bytes, and a 1 TB database contains 240 (1 099 511 627 776) bytes. However, a 1 kbps communication channel transmits 1000 bits per second and a 1 Gbps LAN runs at 1 000 000 000 bits/s because speeds are not powers of two. Many people tend to mix up these two systems.
We'll use the symbols KB, MB, and GB for 210, 220, and 230 bytes, respectively, and the symbols kbps, Mbps, and Gbps for 103, 106, and 109 bits/s, respectively.

Table 7: Units of Data Storage
Unit Definition Example
Bit (b) Binary digit, 1 or 0 On / Off; Open / Closed; +5V / 0V
Byte (B) 8 bits Represent the letter "E" as ASCII code
Kilobyte (KB) 1 KB = 1024 B Typical Email = 2KB
Megabyte(MB) 1 MB =1024 KB = 1 048 576 B Floppy Disks = 1,44 MB; Typical song in MP3 format = 5 MB
Gigabyte (GB) 1 GB = 1024 MB = 1 073 741 824 B Typical Hard Drive = 40 GB or greater
Terabyte (TB) 1 TB = 1024 GB = 1 099 511 627 776 B Database; Amount of data theoretically transmittable in optical fiber in one second