Digression: Binary Addition Representing characterssud/COMP4/lectures/lecture07/lec07.pdf · 010 =...
Transcript of Digression: Binary Addition Representing characterssud/COMP4/lectures/lecture07/lec07.pdf · 010 =...
Summer II 2005, Page 1 Lec-07
COMP 4—Power Tools for the Mind 1What’s in the box?
Representing Concepts Part 2--What we’ll cover for Part 2 :
• Representing concepts in a computer– 1st type: Numeric values --brief review– Today: How are some of the other
concepts represented in the box?
1234
COMP 4—Power Tools for the Mind 2What’s in the box?
Information theory: Study of the most efficient way to encode concepts: information that interests us.– All information must be captured & stored, processed, and
transmitted.– Using numbers to represent information allows us to use a
discrete symbol system: distinct, unambiguous, precise.– Discrete numbers are much easier to engineer than
continuous numbers.
Quick review of Part 1:• How do we represent numeric values such as
1378 or 17.2351 in a computer?– Logical structure? Physical structure?– Mathematical operations (add, subtract, multiply,
divide) operate on numeric information.
COMP 4—Power Tools for the Mind 3What’s in the box?
Digression: Binary Addition
Sum:
1 0 1 1base 2
1 1 1 1base 2
0
1Carry:
1
1
0
1
11
Rules• 0 + 0 = 0• 1 + 0 = 0 + 1 = 1• 1 + 1 = 1 0
COMP 4—Power Tools for the Mind 4What’s in the box?
Representing characterscharacters
• With unique bit patterns, we can represent any character (including foreign characters), just the way we already used unique bit patterns to represent decimal values……
–Digression: the program determines if a stored bit pattern represents a numeric value, or an alphanumerictext, or part of a sound, or part of a picture, or part of an instruction.....
• A - Z a - z 0 - 9 ! @ # $ % ^ & * ( ) + =• Must work with binary coding schemes (why?)
COMP 4—Power Tools for the Mind 5What’s in the box?
• However: Bit patterns that represent characters(alphanumeric) are typically not used used for mathematical computations like add or subtract.
• Instead: alphanumeric characters are mostly used to store textual content, which may be sorted or concatenated.
• So: although both numeric values (used for counting & math) and alphanumeric characters(used for text) are both represented using a bit pattern, they are treated differently.
Another digression:
COMP 4—Power Tools for the Mind 6What’s in the box?
– Number characters (alphanumeric) are treated by the computer as text characters:• 9 not= “9”
• 9 + 9 = 18 while “9” + “9” = “99”
The Binary pattern that represents 9 is different from the binary pattern that represents “9”.
– yet sorting is possible because text characters also have a binary (numeric) value:
The numeric value of the binary representation of A is smaller than B and also B is smaller than C and so on …
Consider:
Summer II 2005, Page 2 Lec-07
COMP 4—Power Tools for the Mind 7What’s in the box?
Letter BBin binary code
Letter BB“in the box”
128 64 32 16 8 4 2 1 “Place”“0” 0 1 0 1 0 0 0 0“1” 0 1 0 1 0 0 0 1“2” 0 1 0 1 0 0 1 0
“A” 0 1 0 0 0 0 0 1“B” 0 1 0 0 0 0 1 0
How to represent C C ??? NOTICE how A < B < C ……
“C” 0 1 0 0 0 0 1 1
COMP 4—Power Tools for the Mind 8What’s in the box?
Number of symbols possibleRemember?x bits could represent 2x numbers2 bits ⇒ 22 = 4 different bit patterns
4 bits? ⇒ 16 different
[24 = 16]
Bit pattern0000000100100011010001010110011110001001101010111100110111101111
Decimal value0123456789
101112131415
SAME THING when representingalphanumeric characters:A two-bit code (two bulbs) can represent(e.g. encode) four unique characters.
COMP 4—Power Tools for the Mind 9What’s in the box?
0 0= A
B0 1
=
C1 0
=
D1 1
=
22 = 4Base # bits = number
of unique combinations
(that represent values)
COMP 4—Power Tools for the Mind 10What’s in the box?
Base# of bits used = number of unique symbols thecoding scheme can represent
Bit pattern length
LOGICAL Representation (bit coding scheme):
#-of-States # of bulbs = number of unique symbols the bulbs can represent
How many bulbs (switches, transistors, vacuum tubes, magnetized locations on disk, ...)
PHYSICAL Representation (hardware “bits”):
CORRESPONDS DIRECTLY to the
COMP 4—Power Tools for the Mind 11What’s in the box?
What if we use more expensive light bulbs? OFF LOW HIGH
#-of-States # of bulbs = number of unique combinations; which indicates number of unique values the bulbs can represent
QUICK! Would that allow us to represent/encode MORE or LESS unique things? WHY? (assume will use only 2 bulbs)
0 0= A
B
C
D
0 1
0 2
1 0=
=
=
1 1= E
F
G
H
1 2
2 0
2 1
=
=
=
2 2= I
Then what has changed? Not how many bulbs, but what?
32 = 9 combinations COMP 4—Power Tools for the Mind 12What’s in the box?
What if we don’t want to use complicated bulbs---how else can we INCREASE how many things can be represented??So, base (# of states) is two: (0 , 1) (off , on) NOW what MUST change?
= H?1 1 1
1 1 00 0= A
0
0 0= B
1
0 1 0= C
0 1= D
1
1 0= E
0
1 0 1= F
= G
23 = 8 combinations
Base# of bits used = number of unique things thecoding scheme can represent
#-of-States # of bulbs = number of unique combinations; which indicates number of unique things the bulbs can represent
Summer II 2005, Page 3 Lec-07
COMP 4—Power Tools for the Mind 13What’s in the box?
So, to get morethings
represented, we just keep adding bits
(or light bulbs)
22 = 4 combinations23 = 8 “24 = 16 “25 = 32 “26 = 64 “27 = 128 “28 = 256 “
216= 65536 “
.... ....
COMP 4—Power Tools for the Mind 14What’s in the box?
For alphanumeric character values:
Bit pattern0101 0000 0101 00010101 00100101 0011(etc)
0100 00010100 00100100 00110100 01000100 0101(etc)
Character (text) value0 123
(etc)
ABCDE
(etc)
7, 8, 16, 32, and 64-bit patterns are used for alphanumeric character values:
27= 128 character values
28= 256 character values
216= 65,536 character values
232= > 4 billion char values
264= 18,446,744,073,709,551,616 character values
14
COMP 4—Power Tools for the Mind 15What’s in the box?
Challenge 1: 26 upper-case characters in our alphabet. Want our electronic word processor to manipulate all 26.
2
What two parts of the equation do we already know?Base# bits used = no. of unique things coding scheme can represent
States# bulbs used = no. of unique things coding scheme “ “
– Must create binary coding scheme that will allow us enough unique patterns to encode all 26.
• What is the minimum bit pattern length that is required for our coding scheme? (minimum number of bulbs)
x=5 (25=32)>= 26 x
COMP 4—Power Tools for the Mind 16What’s in the box?
Challenge 2: there are X number of characters in Zuni alphabet. Want our word processor to manipulate all of them.
• A binary coding scheme, which is six bits long, would allow enough unique patterns to be able to manipulate all the characters of the Zuni alphabet.
• Maximum number of characters in the Zuni alphabet?
Base# of bits used = no. of unique things coding scheme can represent
What parts do we already know?
26 >= X X=64
COMP 4—Power Tools for the Mind 17What’s in the box?
• ASCII and Extended ASCII (ANSI):– Standard ASCII: Basic set for character data:
7-bit code• can represent how many characters?
– ANSI: Extended ASCII to 8-bits. (Windows apps use 8 bits)
• can represent how many characters?• 8 bits: each pattern also fits nicely into 1 memory cell.
128
256
Character formats
COMP 4—Power Tools for the Mind 18What’s in the box?
8-bit ASCII0 0101 00001 0101 00012 0101 0010A 0100 0001B 0100 0010C 0100 0011
Hello01001000 01100101 01101100 01101100 01101111In 8-bit ASCII code:
8 bits: one byte (one character): logical8 bulbs: stores one byte: physical
In the box (memory or storage):
17
Summer II 2005, Page 4 Lec-07
COMP 4—Power Tools for the Mind 19What’s in the box?
• Other codes– Unicode: 16-bit code (65,536 bit patterns)– Internat’l Standards Org: 32-bit code (>4 billion
bit patterns)
Quotable...
Representing other information types… pictures, sounds
COMP 4—Power Tools for the Mind 20What’s in the box?
Important digression:– Data can travel and be stored in the form of a signal.
• Signal: anything that changes with time or space.
– Different types of signals: • Analog: continuous values (measurable)
– Most of what we see/hear is in ANALOG form: sound, light, water, electricity, temperature, wind: can be plotted as a continuous, undulating line or wave.
0 time
• Digital: discrete values (countable, like numbers)
0 time
COMP 4—Power Tools for the Mind 21What’s in the box?
Converting analog info to digital form:• Most natural forms of information (pictures,
sounds) are in analog form--continuous values– E.g.: Sound: how loud? How high? (pitch)– E.g.: Color: GRAY . But how GRAY is it?
• No precise way in analog world to determine this perfectly and the same each time. G G G G
• Computers: designed to store and process (and transmit) discrete, on/off signals.
• So with digital computers, we’ll have to change analog signals with infinite precision into digital signals with finiteprecision.
• That process is called “digitizing” (or “sampling”).
COMP 4—Power Tools for the Mind 22What’s in the box?
Advantages of digital (over analog)• Digital signals offer the following, and more…
– Known Precision – Ordinality (built-in order of numbers)
• Shades from darkest to lightest are expressed as numbers,from smallest to largest.
• Example: Eight shades to work with, from black to white:
0 1 2 3 4 5 6 7000 001 010 011 100 101 110 111
– Absolute perfect replication• Analog: Copy of a copy of a copy…..last as good as original?
– Content analysis much easier– Compression techniques work well (later!!)
COMP 4—Power Tools for the Mind 23What’s in the box?
Images; graphicsComputer images: formed by collections of
dots; each dot is a picture element: pixel. How image is represented & stored inside
the computer (logical structure) can be radically different.
1. Bitmapped: Also called Raster2. Object-oriented: Also called Vector– Each has its own advantages, disadvantages, and
particular uses.
Representing visual infovisual info • Bitmap graphics
Phys’l:Log’l: 000 001 010 011 100 101 110 111
0 1 2 3 4 5 6 7 Dec’lBinary
– Image is represented by bits.– Each bit pattern defines one pixel.– Good illustration: SCANNER
• Regular photograph. What kind of information is it?
• What kind of information can be stored and manipulated inside a digital computer?
• Essentially, then, what does your SCANNER have to do?
• In laymen’s terms, how?
23
Summer II 2005, Page 5 Lec-07
COMP 4—Power Tools for the Mind 25What’s in the box?
– Stored representation of such a picture: “bitmap” or “pixmap”
• Stored bits are like a map of image being represented.
Physical representation of bits are actually stored in memory.
Bitmap
B&W Image
• Program? Knows nothing about shapes of objects; only which pixels are what color value (more shortly…)
24 COMP 4—Power Tools for the Mind 26What’s in the box?
– Monochrome (Black&White). • If a single pixel can
be either black orwhite, then how manybits are needed torepresent one pixel?
Why?
0 1
25
– Grayscale• What if we want to represent more? Say, shades of gray.
What has to happen to the bits stored in memory in order to represent more different values (shades) on the screen?
Intuitively: LESS or MORE bits/pixel than with B&W?• ILLUSTRATION: If a single pixel can be any one of
eight shades, what minimum # of stored bits is needed to represent that one pixel? (Length of coding scheme?)
000 001 010 011 100 101 110 111
OK, what about binary bits? Are two bits enough?2? = 8 unique “shades” (or values of gray)
00 01 10 11 ? ?0 1 2 3 4 5 6 7
262? = 256 unique “shades” (or values of gray) COMP 4—Power Tools for the Mind 28What’s in the box?
Editing bitmaps
COMP 4—Power Tools for the Mind 29What’s in the box?
Base# of bits used = number of unique concepts/valuesthe coding scheme can represent
Bit pattern lengthREMEMBER BACK?Number of shades possible
Base# of bits used = number of unique shades/colorsthe coding scheme can represent
Bit pattern length
NOTICE a PATTERN HERE ? 28 COMP 4—Power Tools for the Mind 30What’s in the box?
– Color Primary colors for computer graphics:RGB
– Digression: Why RGB?
For more information:Primary colors http://www.beer.org/~tpark/color.html
How colors work:http://www.rgbworld.com/color.html
The additive reproduction process mixes various amounts of R, G and B light to produce other colors.
Representing color
29
Summer II 2005, Page 6 Lec-07
COMP 4—Power Tools for the Mind 31What’s in the box?
“True” color uses a 24 bit code to represent each color value: (photographic quality)
–8 bits for red (28 = 256 shades of red)–8 bits for green (28 = 256 shades of green)–8 bits for blue (28 = 256 shades of blue)
Combine various shades to make various color combinations (provides lots of bit patterns).
• SO: If one pixel is represented by a 24-bit code, how many different COLOR VALUES can a single pixel display?
224 = ? ~16.7 million unique color values.
8 bits 8 bits 8 bits
30 COMP 4—Power Tools for the Mind 32What’s in the box?
LOOKING IN THE BOX: 24 bits stored for EACH PIXEL!
000000000000000000000000 = BLACK
Again, imagine an advancing odometer that would show allof the color valuesbetween black and white …!
= All OFF
111111111111111111111111 = WHITE= All ON
000000000000000000000001000000000000000000000010000000000000000000000011000000000000000000000100000000000000000000000101000000000000000000000110000000000000000000000111000000000000000000001000
AND LOTS MORE!
COMP 4—Power Tools for the Mind 33What’s in the box?
– File format : How information is encoded & stored
– Different software apps understand different graphics file formats (encoding systems).
– TIFF, GIF, JPEG, BMP,... – Some better for certain purposes... Beyond the scope of COMP 4.
– When saving an image file one can usually choose a file format from a selection.
– PowerPoint, for example, recognizes a number of graphics file formats, but not all.
– However, utilities (filters) can interpret and convert one file format to another. Software often comes w/filters (or can download from software vendor’s Web site).
File formats for bitmap graphics
COMP 4—Power Tools for the Mind 34What’s in the box?
–Advantages, disadvantages, applications:
Original bitmapped
graphic
Same image scaled up
–Photo realism.–Software: Photo editing, and Paint.
–Can work at pixel level. –HUGE files without compression!
–Storage and download time!–Images do not scale up well:
–Image resolution is important
COMP 4—Power Tools for the Mind 35What’s in the box?
Vector graphics– Uses instructions to draw lines, fill shapes (rather
than tracking and storing bits for each pixel)…. In English: “Draw a circle at the point that is 100 pixels to the
right and 140 pixels down from the top-left corner of the screen with the radius of 25 pixels.”
– Software: Drawing. • Shapes are known to the program. Does not work at pixel
level, but rather at object-level.
– Scalable, no jaggies.– Files relatively small– Layering: “2 ½ dimensions”– Seeing more vector graphics for the Web: .sfv, .cmg
COMP 4—Power Tools for the Mind 36What’s in the box?
another important means of conveying information.– Produced by vibration; transmitted over a medium.
• Sound travels in analog wave patterns.• Wave characteristics: amplitude (loudness) and
frequency (pitch) can be measured & sampled over time, and stored as a sequence of binary numbers.
• Called? “Digitizing” or “sampling”– Much like scanning an analog photograph spatially
creates a digital bitmap.
• The higher the sampling rate, the better the quality of the digital signal!
Representing soundsound
Summer II 2005, Page 7 Lec-07
COMP 4—Power Tools for the Mind 37What’s in the box?
• Captured in analog form by an analog microphone• Converted to digital form by an ADC (audio to digital converter)• Stored as file on a digital storage device (CD or hard drive). Then, for playback to human ears:• Converted to analog form by a DAC (digital to analog converter)• Played back by analog speakers.
Samples
0 time
dB
Samplingrate
Analog to digital audio
Analog sounds can be:
COMP 4—Power Tools for the Mind 38What’s in the box?
These days, we can get – Digital capture and player devices for both audio and
video.• Digital cameras• Digital camcorders• Digital microphones
– So, for that data, the computer does not need ADC or DAC converters:
captured and played all in the same digital mode.
• MP3 files: file format that squeezes digital sound into small files through sophisticated compression adapted to the human ear (more later). Fast to download; less to store.
COMP 4—Power Tools for the Mind 39What’s in the box?
SUMMARY!– We can use bit patterns of zeroes and ones to
represent:• Numeric values• Alphanumeric text• Pictures (bitmaps)• Soundsand• Instructions
– Vector graphics; MIDI (music); General programming (coming)
RECAP: SOFTWARE determines if a stored bit patternrepresents a numeric value, or alphanumeric text, or part of a sound, or part of a picture, or part of an instruction..... all bits look the same to the CPU!