| < Day Day Up > |
|
Humans use a base 10 numbering system. Computers operate using a base 2 numbering system called binary. Binary works well with computers because there are only two values, or digits, that a computer recognizes: 0 and 1.
As you may recall from Chapter 4, the smallest unit of measure in a computer is a negative or positive electrical charge held in a cell within a capacitor. If an electrical charge is negative, a 0 digit is represented. If the charge is positive, a 1 is represented. A 0 or a 1 represents a single bit. There are 8 bits (combinations of 0s and 1s) in 1 byte. In human terms, a computer uses 1 byte of information to determine a single character, symbol, space, number, or letter. A group of bytes together form a word.
There are two ways to convert a binary number to a decimal number, or a decimal number to binary. The simplest way is to use a scientific calculator. The default software calculator installed by most versions of Windows is handy for this task. Click Start > Programs > Accessories > Calculator, and change the view to scientific. Enter a number in decimal and click the radio button Bin; the decimal number will be converted to binary. Click the radio button Dec to convert the binary number back to a decimal number. The Windows calculator can also be used to convert decimal numbers to hexadecimal format. (Hexadecimal notation is discussed later in this chapter.) Use the Hex radio button for this purpose.
Manually converting a binary number to decimal is a little more difficult. Figure 5.1 represents an 8-bit byte, 00101101. The top row of numbers in the figure represents base 2 increments (increasing powers of 2, from right to left). To convert the binary number 00101101 to a decimal number, simply multiply the 0s and 1s by their corresponding power of 2. Add the eight results together and you will have the decimal equivalent to 00101101. You can replace the binary number 00101101 in Figure 5.1 with any combination of bits to calculate a different binary number's decimal equivalent. See Table 5.1 for examples of other binary numbers and their decimal equivalents.
Figure 5.1: Eight-bit byte and base 2 increments.
Use Figure 5.1 to calculate the decimal equivalent of 00101101 by multiplying the 0s and 1s by their corresponding power of 2.
0 x 128 = 0
0 x 64 = 0
1 x 32 = 32
0 x 16 = 0
1 x 8 = 8
1 x 4 = 4
0 x 2 = 0
1 x 1 =1
Add the eight results together:
0 + 0 + 32 + 0 + 8 + 4 + 0 + 1 = 45 (the decimal equivalent of 00101101)
Binary Number | Decimal Equivalent |
---|---|
00000000 | 0 |
00000001 | 1 |
00000010 | 2 |
00000011 | 3 |
00000100 | 4 |
00001010 | 10 |
| < Day Day Up > |
|