Assignment 1:
Due Monday, January 31
A brief summary of integers, floats and binary representation.
Computers store numbers in binary format (base 2) as a series of 1 and 0. The individual 0 and 1 are called bits. The bits are usually sored in groups of eight called bytes. This representation can store integer numbers exactly as long as the number is not too large. A standard integer consists of 4 bytes while a short integer consists of only 2 bytes. A short integer (16 bits long) can store a number up to 65536 (or 2 to the power 16). By using one bit as a sign bit (plus or minus) positive and negative numbers (2 to the power 15 since 1 bit is already used) can be stored. A single byte can store the numbers 0 to 255. Numbers with decimals cannot be stored as integers and must be stored in floating point representation with a mantissa and exponent. Floating points representations unavoidably round off some numbers and lead to "round-off" error. Standard floating point representation is 4 bytes longs. The accuracy can be increased by using double precision, which uses 8 bytes to store a floating point number. Double precision is necessary for many scientific calculations.
The ASCII chart
| 0 NUL | 1 SOH | 2 STX | 3 ETX | 4 EOT | 5 ENQ | 6 ACK | 7 BEL |
| 8 BS | 9 HT | 10 NL | 11 VT | 12 NP | 13 CR | 14 SO | 15 SI |
| 16 DLE | 17 DC1 | 18 DC2 | 19 DC3 | 20 DC4 | 21 NAK | 22 SYN | 23 ETB |
| 24 CAN | 25 EM | 26 SUB | 27 ESC | 28 FS | 29 GS | 30 RS | 31 US |
| 32 SP | 33 ! | 34 " | 35 # | 36 $ | 37 % | 38 & | 39 ' |
| 40 ( | 41 ) | 42 * | 43 + | 44 , | 45 - | 46 . | 47 / |
| 48 0 | 49 1 | 50 2 | 51 3 | 52 4 | 53 5 | 54 6 | 55 7 |
| 56 8 | 57 9 | 58 : | 59 ; | 60 < | 61 = | 62 > | 63 ? |
| 64 @ | 65 A | 66 B | 67 C | 68 D | 69 E | 70 F | 71 G |
| 72 H | 73 I | 74 J | 75 K | 76 L | 77 M | 78 N | 79 O |
| 80 P | 81 Q | 82 R | 83 S | 84 T | 85 U | 86 V | 87 W |
| 88 X | 89 Y | 90 Z | 91 [ | 92 \ | 93 ] | 94 ^ | 95 _ |
| 96 ` | 97 a | 98 b | 99 c | 100 d | 101 e | 102 f | 103 g |
| 104 h | 105 i | 106 j | 107 k | 108 l | 109 m | 110 n | 111 o |
| 112 p | 113 q | 114 r | 115 s | 116 t | 117 u | 118 v | 119 w |
| 120 x | 121 y | 122 z | 123 { | 124 | 125 } | 126 ~ | 127 DEL |
1.) How many different characters are there? What power of two is this number?
On a computer, do you think integers or floats are used represent characters?
(hint 22 = 4, 23 = 8, 24 = 16, 25 = 32)
2.) Write out the NUL and SOH numbers in their bit (binary) representation.
3.) If each ASCII character uses 8 bits (1 byte), how many bytes does your name
take up?
4.) There are two ways to represent written numbers on a computer, binary and
ASCII. With two-byte integers, the largest possible number is 65536 (=216) [binary
representation]. If the number 65536 were written in ASCII instead, how many
bytes would it require (assuming each ASCII character requires 1 byte)?
5.) If you scan in a 8-inch by 10-inch picture using a resolution of 300 dots
per inch (dpi),
a) How many dots (pixels) will be needed?
b) Suppose each dot is represented by a number between 0 and 255, (0 is black
and 255 white and the numbers in between are varying scales of gray), would
you use a one-byte or two-byte integer?
c) How many bytes are needed for the file?
d) Suppose you scan at 600 dpi - how many bytes are needed?
e) If the picture is color, with 3 integers for each dot (each number representing
red, green, or blue), how many bytes are needed for the 600 dpi image?
f) If the picture is changed but the size (2-inch by 2-inch) remains the same,
will the file size change?
6.) One kilobyte (KB) is 1,024 bytes.
a) How many KB are needed for the 300 dpi grayscale scan in question 5c?
b) If you have a modem that works at 56 KB per second, how many seconds will
it take to transmit the file?
7.) The USGS has a digital elevation model (DEM) of the earth with a 3 arc-second
resolution (60 seconds in a minute, 60 minutes in one degree). This means the
surface topography of the entire earth (including ocean) is converted into numbers,
with each point spaced 3 seconds apart. If each point uses 2 byte signed integers,
how many bytes will the entire DEM require? What is the maximum and minimum
elevation above and below sea level that can be stored. How many 700-MB CD disks
will it take to store it?
8) Young human ears can hear up to about 20,000 Hz (20,000 cycles per second).
Sampling theory says that the sample rate must be at least twice the highest
frequency. Therefore, to perfectly (so that the average young human cannot tell
the difference) reproduce music in digital format it must be sampled at 40,000
Hz or, in other words, 40,000 samples per second. If we assume that each sample
is represented by a 2byte integer, how many bytes will it take to store a 2
minute song?