Download Representation of text and code

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Approximations of π wikipedia , lookup

Addition wikipedia , lookup

Location arithmetic wikipedia , lookup

Arithmetic wikipedia , lookup

Positional notation wikipedia , lookup

Transcript
( THE
CS 115: COMPUTING FOR
SOCIO-TECHNO WEB
REPRESENTATION OF
TEXT, NUMBERS AND CODE
TODAY
Computer components
Binary numbers
Text representation
LOOKING UNDER THE HOOD
OPENING THE BLACK BOX
COMPUTER
ARCHITECTURE
A SIMPLE COMPUTER
Fetch the next
instruction from
memory
Decode it
Execute it
REPEAT ad infinitum
BINARY NUMBERS
BITS: 0 AND 1
The “blood” of the computer
Only 2 bits:
electric current passes or does not through a wire.
Only 2 bits: we use symbols 0 and 1
Still enough to represent anything:
•
•
•
•
Numbers
Letters
Instructions
Images, videos, music, …
Unbelievable? Amazing?
OUR POSITIONAL
DECIMAL SYSTEM
•
•
•
•
•
•
Positional: The position of a digit has specific meaning.
You know that
1492 = 1*1000 + 4*100 + 9*10 + 2*1 (duh!)
We really mean
1492 = 1*103 + 4*102+ 9*101 + 2*100 (aha!)
We really need a symbol for 0 in order to do that!
The decimal system is great for arithmetic (if you are human)
Computer use a binary system
UNDERSTANDING
POWERS OF 2
Like with our decimal system, we
can represent any number in binary
using powers of 2:
• 1010 = 1*8 + 0*4 + 1*2 + 0*1 (= 10)
• 1010 = 1*23 + 0*22 + 1*21 + 0*20 (= 10)
The first 10 powers of 2:
x
2x
1
2
2
4
3
8
4
16
5
32
6
64
7
128
8
256
9
512
10
1024
ANYWAY, IF YOU HAVE
TWO SYMBOLS…
Position of digit signifies contribution of (the
corresponding) base power
Base 10
• 1492 = 1*1000 + 4*100 + 9*10 + 2*1
• 2009 = 2*1000 + 0*100 + 0*10 + 9*1
Base 2:
• 1010 = 1*8 + 0*4 + 1*2 + 0*1 (= 10)
• 0111 = 0*8 + 1*4 + 1*2 + 1*1 (= 7)
Activity: creating binary numbers
You can represent any number!
HOW MANY BITS
DO YOU NEED?
Bit depth
Can repr.
Bit depth
21
22
23
24
25
26
27
28
29
2
210
4
8 Byte ~ 101 220
16
32
230
64
128
256
512
Can represent up to…
1024
Kilobyte ~ 103
1,048,576
Megabyte ~ 106
1,073,741,824
Gigabyte ~ 109
QUANTITIES OF
BYTES
HAPPY BIRTHDAY TO ?
1100
11101110010
/
1001
/
REPRESENTING TEXT
… you can represent any character
A is repr’d by 65, or 01000001
Hi! is repr’d by 72 105 33, or 010010000110100100100001
ASCII CODE
HOW MANY ASCII
CHARACTERS?
8 BITS EACH, SO THERE ARE IN ALL
=
2
256
8
17
February 2, 2009
… OF ANY LANGUAGE THAT
EXISTS OR EVER EXISTED
UNICODE
20
HOW MANY UNICODE
CHARACTERS?
32 BITS EACH, SO THERE ARE IN ALL
21
32
=
2
4,294,967,296