Lecture 12
Announcements
Mathematics Seminar Tuesday at 3:15 PM
Pete Schumer,
"Aspects of the Josephus Problem"
Exam 1: Tomorrow in Lab
One Sheet of Paper ( 1 side) with Notes
Short Answer, Short Essays, HTML Code
Today:
Bits, Bytes, and Binary
III
Color and Your Computer
Bits, Bytes, and Binary
III
BIT = Binary Digit
= 0 or 1
BYTE = Ordered Sequence of 8 Bits
example: 01001101
As a Base 2 (binary)Number:
010011012 = 26 + 23 + 22 + 20 = 64 + 8 + 4 + 1 = 77
77 = ASCII Code for M
A kilobyte (1 KB) is defined as 210 = 1024 bytes.
1 KB = 210
bytes= 1024 ~ 1000 bytes
A megabyte (1 MB) is 210 kilobytes:
1 MB = 210 KB = 210 210 bytes
= 220 bytes = 1,048,576 bytes
~ 1,000,000 bytes.
Rough Conversion: 210 ~ 103
Example:220
= 210 210 ~ 103 103 = 106
Computer Memory: 64 MB
Floppy Disk: 1.44 MB
Zip Disk: 100 MB
A gigabyte (1 GB) is 210 megabytes:
1 GB = 210 MB = 210 220 bytes
= 230 bytes = 1,073,741,824 bytes
~ 1,000,000,000 bytes. (1 billion bytes)
Storage Space on Hard Drive: 20GB
CD-ROM : 650 MB
Human Terms:
A densely packed single spaced typed sheet of paper = 60 lines @ 80 characters
= 4800 characters ~ 5
KB
Alice in Wonderland:
27,808 words
148,491 characters ~ 150
KB
Other Number Systems
Question: What does 100 mean?
Answer: The meaning depends on the base
Base 10
(100)10
= 1 ¥
102
+ 0 ¥
101
+ 0 ¥
100
Base 2
(100)2
= 1 * 22 + 0 * 21
+ 0 * 20 = 4
Base 5
(100)5= 1 * 52 + 0 * 51 + 0 * 50 = 25
Base 16
(100)16= 1 * 162 + 0 * 161 + 0 * 160 = 256
Note: Base may be larger than 10.
Available Digits:
Base 2: 0,1
Base 5: 0,1,2,3,4
Base 10: 0,1,2,3,4,5,6,7,8,9
Base 16: 0,1,2,3,5,6,7,8,9,?,?,?,?,?,?
Hexadecimal (Base 16)
0,1,2,3,5,6,7,8,9,A,B,C,D,E,F
Counting to 20
Base 10 | Base 2 | Base 5 | Base 16 |
1 | 1 | 1 | 1 |
2 | 10 | 2 | 2 |
3 | 11 | 3 | 3 |
4 | 100 | 4 | 4 |
5 | 101 | 10 | 5 |
6 | 110 | 11 | 6 |
7 | 111 | 12 | 7 |
8 | 1000 | 13 | 8 |
9 | 1001 | 14 | 9 |
10 | 1010 | 20 | A |
11 | 1011 | 21 | B |
12 | 1100 | 22 | C |
13 | 1101 | 23 | D |
14 | 1110 | 24 | E |
15 | 1111 | 30 | F |
16 | 10000 | 31 | 10 |
17 | 10001 | 32 | 11 |
18 | 10010 | 33 | 12 |
19 | 10011 | 34 | 13 |
20 | 10100 | 40 | 14 |
What is the decimal equivalent of the hexadecimal 2F?
2F = 2 ¥ 161 + F ¥ 160
= 32 + 15 = 47
Find Hexadecimal representation of 1492
Powers of 16: 16 256 4096 65536
1492 = 5 ¥ 256 + 212
= 5 ¥ 256 + 13 ¥ 16 + 4
= 5 ¥ 162 + D¥ 161+ 4¥ 160
= 5D4
Byte:
1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 |
16 possibilities 16 possibilities
(Represents 128 + 64 + 16 + 4 + 2 + 1 = 215)
Left Side: 1101 -> 8 + 4 + 1 = 13 -> D in Hex
Right Side: 0111 -> 4 +2 + 1 = 7 -> 7 in Hex
Write as D716
(= 13*16 + 7 = 208 + 7 = 215)
A Brief Review of Color
Color is represented on a computer by specifying levels of the three primary colors Red, Green and Blue (RGB).
Example: In HTML:
<BODY BGCOLOR = "#CDA732" >
There are 256 levels of each primary.
Number of different possible colors
28 28 28 = 224 = 24 210 210 ~ 16,000,000
This is known as "24-bit" color
Leftmost 2 amount of Red
Middle 2 amount of Green
Rightmost
2
amount of Blue
white | #FFFFFF | red | #FF0000 | cyan | #00FFFF |
black | #000000 | green | #00FF00 | magenta | #FF00FF |
gray | #888888 | blue | #0000FF | yellow | #FFFF00 |
How Does a Computer Store Numbers, Text, and Images?
A Computer uses numbers (expressed in binary) to represent internally everything it does.
Whole Numbers
(0,1,2,3,..) are easy: Use the binary representation for the number.
(Need to worry about
negative numbers and decimals).
Text:
Text consists of characters and each character has an ASCII code which
is a whole number.
Images: Also relatively easy
Screen is made up of
rows and columns of pixels (picture elements)
(A) Black and White:
Circle:
• | • | • | • | ||||||||||||
• | • | • | • | ||||||||||||
• | • | ||||||||||||||
• | • | ||||||||||||||
• | • | ||||||||||||||
• | • | ||||||||||||||
• | • | ||||||||||||||
• | • | ||||||||||||||
• | • | ||||||||||||||
• | • | ||||||||||||||
• | • | ||||||||||||||
• | • | ||||||||||||||
• | • | ||||||||||||||
• | • | ||||||||||||||
• | • | • | • | ||||||||||||
• | • | • | • |
Internal Representation:
1 if pixel is "on" and 0 if pixel is "off"
0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
Need: 1 bit per pixel
The "Jaggies" you see on a computer screen are a consequence of the resolution of the screen (the number of pixels per inch).
Color: 24 bits per pixel
Example: Image:
220 x 280 pixels = 61,600 pixels
1 pixel needs 3 bytes
Hence we need 184,800 bytes ~ 184
KB