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 0001 = 1 0010 = 2 0011 = 3 0100 = 4 0101 = 5 0110 = 6 0111 = 7 1000 = 8 1001 = 9 1010 = 10 1011 = 11 1100 = 12 1101 = 13 1110 = 14 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 ------048 049 050 051 052 053 054 055 056 057 065 066 067 068 069 070 071 072 Octal ----060 061 062 063 064 065 066 067 070 071 101 102 103 104 105 106 107 110 Hex --030 031 032 033 034 035 036 037 038 039 041 042 043 044 045 046 047 048 Binary -----00110000 00110001 00110010 00110011 00110100 00110101 00110110 00110111 00111000 00111001 01000001 01000010 01000011 01000100 01000101 01000110 01000111 01001000 Value ----0 1 2 3 4 5 6 7 8 9 A B C D E F G H 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 111 112 113 114 115 116 117 120 121 122 123 124 125 126 127 130 131 132 141 142 143 144 145 146 147 150 151 152 153 154 155 156 157 160 161 162 163 164 165 166 167 170 171 172 049 04A 04B 04C 04D 04E 04F 050 051 052 053 054 055 056 057 058 059 05A 061 062 063 064 065 066 067 068 069 06A 06B 06C 06D 06E 06F 070 071 072 073 074 075 076 077 078 079 07A 01001001 01001010 01001011 01001100 01001101 01001110 01001111 01010000 01010001 01010010 01010011 01010100 01010101 01010110 01010111 01011000 01011001 01011010 01100001 01100010 01100011 01100100 01100101 01100110 01100111 01101000 01101001 01101010 01101011 01101100 01101101 01101110 01101111 01110000 01110001 01110010 01110011 01110100 01110101 01110110 01110111 01111000 01111001 01111010 I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z