How Computers Store Numbers
Computer systems are constructed of digital electronics. That means that their electronic circuits can exist in only one of two states: on or off. Most computer electronics use voltage levels to indicate their present state. For example, a transistor with five volts would be considered "on", while a transistor with no voltage would be considered "off." Not all computer hardware uses voltage, however. CD-ROM's, for example, use microscopic dark spots on the surface of the disk to indicate "off," while the ordinary shiny surface is considered "on." Hard disks use magnetism, while computer memory uses electric charges stored in tiny capacitors to indicate "on" or "off."
These patterns of "on" and "off" stored inside the computer are used to encode numbers using the binary number system. The binary number system is a method of storing ordinary numbers such as 42 or 365 as patterns of 1's and 0's. Because of their digital nature, a computer's electronics can easily manipulate numbers stored in binary by treating 1 as "on" and 0 as "off." Computers have circuits that can add, subtract, multiply, divide, and do many other things to numbers stored in binary.
How Binary Works
The decimal number system that people use every day contains ten digits, 0 through 9. Start counting in decimal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, Oops! There are no more digits left. How do we continue counting with only ten digits? We add a second column of digits, worth ten times the value of the first column. Start counting again: 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 (Note that the right column goes back to zero here.), 21, 22, 23, ... , 94, 95, 96, 97, 98, 99, Oops! Once again, there are no more digits left. The only way to continue counting is to add yet another column worth ten times as much as the one before. Continue counting: 100, 101, 102, ... 997, 998, 999, 1000, 1001, 1002, .... You should get the picture at this point.
Another way to make this clear is to write decimal numbers in expanded notation. 365, for example, is equal to 3×100 + 6×10 + 5×1. 1032 is equal to 1×1000 + 0×100 + 3×10 + 2×1. By writing numbers in this form, the value of each column becomes clear.
The binary number system works in the exact same way as the decimal system, except that it contains only two digits, 0 and 1. Start counting in binary: 0, 1, Oops! There are no more binary digits. In order to keep counting, we need to add a second column worth twice the value of the column before. We continue counting again: 10, 11, Oops! It is time to add another column again. Counting further: 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111.... Watch the pattern of 1's and 0's. You will see that binary works the same way decimal does, but with fewer digits.
Binary uses two digits, so each column is worth twice the one before. This fact, coupled with expanded notation, can be used convert between from binary to decimal. In the binary system, the columns are worth 1, 2, 4, 8, 16, 32, 64, 128, 256, etc. To convert a number from binary to decimal, simply write it in expanded notation. For example, the binary number 101101 can be rewritten in expanded notation as 1×32 + 0×16 + 1×8 + 1×4 + 0×2 + 1×1. By simplifying this expression, you can see that the binary number 101101 is equal to the decimal number 45.
An easy way to convert back and forth from binary to decimal is to use Microsoft Windows Calculator. You can find this program in the Accessories menu of your Start Menu. To perform the conversion, you must first place the calculator in scientific mode by clicking on the View menu and selecting Scientific mode. Then, enter the decimal number you want to convert and click on the "Bin" check box to convert it into binary. To convert numbers from binary to decimal, click on the "Bin" check box to put the calculator in binary mode, enter the number, and click the "Dec" check box to put the calculator back in decimal mode.
Representation
Binary numbers and arithmetic let you represent any amount you want using just two digits: 0 and 1. Here are some examples:
Decimal 1 is binary 0001
Decimal 3 is binary 0011
Decimal 6 is binary 0110
Each digit "1" in a binary number represents a power of two, and each "0" represents zero:
0001 is 2 to the zero power, or 1
0010 is 2 to the 1st power, or 2
0100 is 2 to the 2nd power, or 4
1000 is 2 to the 3rd power, or 8.
When you see a number like "0101" you can figure out what it means by adding the powers of 2:
0101 = 0 + 4 + 0 + 1 = 5
1010 = 8 + 0 + 2 + 0 = 10
0111 = 0 + 4 + 2 + 1 = 7
Larger Numbers
Here are the numbers from 0 to 15, in binary:
0000 = 0 0100 = 4 1000 = 8 1100 = 12
0001 = 1 0101 = 5 1001 = 9 1101 = 13
0010 = 2 0110 = 6 1010 = 10 1110 = 14
0011 = 3 0111 = 7 1011 = 11 1111 = 15
To represent bigger whole numbers (integers), you need more bits -- more places in the binary number:
10000101 = 128 + 0 + 0 + 0 + 0 + 4 + 0 + 1 = 133.
That was 8 bits. 8 bits is usually called a "byte", and it's the size usually used to represent an alphabetic character -- "A" is 65, or 01000001
Some other terms you'll hear are:
· kilobyte, which is 1024 bytes (1024 is 2 to the 10th power)
· megabyte, which is roughly a million bytes.
Typical sizes for personal computer RAM (random access memory) are 512 to 1024 megabytes, while hard disks now start around 40 gigabytes. Since each byte can represent one character of the alphabet, that means a hard disk might hold something like 80000 million characters, or 15000 million words of "raw" text. Documents formatted in a word processor take up a lot more space, though, and the operating system and software usually fill at least 100 megabytes.
To represent real numbers, fractions, or very large numbers, binary systems use "floating point arithmetic." That's another topic.
Why Use Them?
For computers, binary numbers are great stuff because:
· They are simple to work with -- no big addition tables and multiplication tables to learn, just do the same things over and over, very fast.
· They just use two values of voltage, magnetism, or other signal, which makes the hardware easier to design and more noise resistant.
ASCII Table
Decimal Octal Hex Binary Value
------
048 060 030 00110000 0
049 061 031 00110001 1
050 062 032 00110010 2
051 063 033 00110011 3
052 064 034 00110100 4
053 065 035 00110101 5
054 066 036 00110110 6
055 067 037 00110111 7
056 070 038 00111000 8
057 071 039 00111001 9
065 101 041 01000001 A
066 102 042 01000010 B
067 103 043 01000011 C
068 104 044 01000100 D
069 105 045 01000101 E
070 106 046 01000110 F
071 107 047 01000111 G
072 110 048 01001000 H
073 111 049 01001001 I
074 112 04A 01001010 J
075 113 04B 01001011 K
076 114 04C 01001100 L
077 115 04D 01001101 M
078 116 04E 01001110 N
079 117 04F 01001111 O
080 120 050 01010000 P
081 121 051 01010001 Q
082 122 052 01010010 R
083 123 053 01010011 S
084 124 054 01010100 T
085 125 055 01010101 U
086 126 056 01010110 V
087 127 057 01010111 W
088 130 058 01011000 X
089 131 059 01011001 Y
090 132 05A 01011010 Z
097 141 061 01100001 a
098 142 062 01100010 b
099 143 063 01100011 c
100 144 064 01100100 d
101 145 065 01100101 e
102 146 066 01100110 f
103 147 067 01100111 g
104 150 068 01101000 h
105 151 069 01101001 i
106 152 06A 01101010 j
107 153 06B 01101011 k
108 154 06C 01101100 l
109 155 06D 01101101 m
110 156 06E 01101110 n
111 157 06F 01101111 o
112 160 070 01110000 p
113 161 071 01110001 q
114 162 072 01110010 r
115 163 073 01110011 s
116 164 074 01110100 t
117 165 075 01110101 u
118 166 076 01110110 v
119 167 077 01110111 w
120 170 078 01111000 x
121 171 079 01111001 y
122 172 07A 01111010 z