How to Represent Numbers on a Computer Digital Data How to Represent Numbers on a Computer
Memory: One Bulb On=Yes Off=No Memory is made up of two-state devices, like a light bulb. One bulb has two states. We could store two things (yes or no). On=Yes Off=No
Two bulbs, four states: Off, off: Off, on: On, off: On, on: No, no No, yes Yes, no Yes, Yes
Three bulbs, eight states: Off, off, off Off, off, on Off, on, off Off, on, on On, off, off On, off, on On, on, off On, on, on
Four bulbs, 16 states:
Pretend they are numbers, where off=0 and on=1: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
How do we interpret the numbers? Base 10 numbers: 10 digits: 0 through 9 Place value is based on powers of 10 ___ ___ ___ ___ ___ ___ 105 104 103 102 101 100 100,000 10,000 1,000 100 10 1
Base 10 1 2 3 4 5 6 . 105 104 103 102 101 100 100,000 10,000 1,000 100 10 1 So 123,456 = 1 * 100,000 = 100,000 2 * 10,000 = 20,000 3 * 1,000 = 3,000 4 * 100 = 400 5 * 10 = 50 6 * 1 = 6 123,456
With 2 digits: Base 2 number system: __ __ __ __ __ __ __ __ 2 digits: 0 through 1 Place value is based on powers of 2 __ __ __ __ __ __ __ __ 27 26 25 24 23 22 21 20 128 64 32 16 8 4 2 1
Base 2 1 0 1 0 1 0 1 0 __ __ __ __ __ __ __ __ 27 26 25 24 23 22 21 20 128 64 32 16 8 4 2 1 So 10101010= 1 * 128 = 128 0 * 64 = 0 1 * 32 = 32 0 * 16 = 0 1 * 8 = 8 0 * 4 = 0 1 * 2 = 2 0 * 1 = 0 170
The first 8 binary numbers (with leading zeros) 0000= 0+0+0+0 = 0 0001= 0+0+0+1 = 1 0010= 0+0+2+0 = 2 0011= 0+0+2+1 = 3 0100= 0+4+0+0 = 4 0101= 0+4+0+1 = 5 0110= 0+4+2+0 = 6 0111= 0+4+2+1 = 7
Binary numbers are represented in BYTES – groups of 8 bits Byte: a group of 8 bits. The basic unit of storage on most computers. 0 = 0000 0000 1 = 0000 0001 2 = 0000 0010 3 = 0000 0011 4 = 0000 0100 5 = 0000 0101 6 = 0000 0110 7 = 0000 0111
Some other binary numbers 0000 0000 = 0 0101 0101 = 1 + 4 + 16 + 64 = 85 1000 0001 = 1 + 128 = 129 1111 1111 = 1 + 2 + 4 + 8 + 16 + 32 +64 + 128 = 255
Need numbers greater than 255? Use two bytes: Smallest number = 0000 0000 0000 0000 Biggest number = 1111 1111 1111 1111 = 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192 + 16,384 + 32,768 = 65,535
Need numbers greater than 65,535? Use 4 bytes: Smallest number: 0000 0000 0000 0000 0000 0000 0000 0000 Biggest number: 1111 1111 1111 1111 1111 1111 1111 1111 = 4,294,967,295
Other numbers There are also ways to represent: Decimal fractions Negative numbers These will be covered elsewhere.
The End