Title: CS149D Elements of Computer Science
1CS149D Elements of Computer Science
Ayman Abdel-Hamid Department of Computer
Science Old Dominion University Lecture 3
9/3/2002
2Outline
- Fractions in Binary
- Storing Integers
- Sign and magnitude (covered last lecture)
- Twos complement (covered last lecture)
- Excess Notation
- Storing Fractions
- Representing Text
- Representing Images
- Data Compression
- By now, we should have covered sections 1.4-1.8
from Brookshear Text
3Fractions In Binary1/3
- Use radix point just like decimal
- To the right of radix point positions are
numbered 1, -2 , .
210 -1-2-3 i 101.101 d
4Fractions In Binary2/3
Express the following in binary notation
- Convert the integer part
- Convert the fraction part. Try to map the
fraction as a sum of power of 2 fractions using
the given denominator as a guide - Put a radix point in between
310 is 112
5Fractions In Binary3/3
- Addition of binary numbers with radix points
- Align radix point
- Apply binary addition process
10.011 100.11
10.011 100.11 __________ 111.001
6Storing Integers1/3
- Binary number system not used as is to actually
store an integer number - Use a numeric storage technique
- Sign and Magnitude
- Problems Two zeros (0, and 0), adding 2 and
2 does not give zero. Straightforward binary
addition does not apply - Twos complement
- Advantages deal with subtractions the same as
additions, simpler hardware to perform integer
arithmetic operations - Excess Notation
7Storing Integers2/3
Excess Notation Excess four notation Bit
pattern Value Unsigned Binary 111
3 7 110 2 6 101 1 5 100
0 4 011 -1 3 010 -2 2 001
-3 1 000 -4 0
- All positive numbers begin with 1
- All negative numbers begin with 0
- 0 is represented as 100
- Unsigned binary value exceeds excess notation by
4, hence the name excess four - Why 4?
- (2of bits 1) 23-1 4
- Smallest negative number is 000
- Largest positive number is 111
8Storing Integers3/3
What is 101 in excess four notation?
101 if interpreted unsigned is 5 101 in excess
four notation is (5-4) 1
What is 3 represented in excess four notation?
Excess four means we need (4-1) 3 bits for
representation Remember unsigned value exceeds
excess notation by 4 Then get unsigned value
34 7 Represent 7 in 3-bit binary 111 3 in
excess four is 111
9Storing Fractions1/6
Need to represent number and position of radix
point Use floating-point notation (Textbook uses
one-byte as example)
- --- ---- 8 bits 1-byte 1 bit Sign bit (0
positive, 1 negative) 3 bits Exponent (encodes
position of radix point) 4 bits Mantissa
(encodes number)
10Storing Fractions2/6
Bit pattern 01101011 in floating-point notation
is what in decimal?
- First bit is 0, then positive
- Exponent is 110 mantissa is 1011
- Extract mantissa and place a radix point on its
left side 0.1011 - Extract exponent and interpret as excess four
notation - 110 in excess four is 2 (make sure?)
- 2 exponent means move radix point to the right
by two bits - (a negative exponent means move radix to left)
- 0.1011 becomes 10.11
11Storing Fractions3/6
Bit pattern 10111100 in floating point is what in
decimal?
- First bit is 1, then negative
- Exponent is 011 mantissa is 1100
- Extract mantissa and place a radix point on its
left side 0.1100 - Extract exponent and interpret as excess four
notation - 011 in excess four is -1 (make sure?)
- -1 exponent means move radix point to the left by
1 bit - 0.1100 becomes 0.01100
12Storing Fractions4/6
What is the following number stored in
floating-point?
- Express number in binary to obtain 1.001 (make
sure?) - Copy bit pattern into mantissa field from left to
right starting with the leftmost 1 in binary
representation - Mantissa is 1001
- Compute exponent to get 1.001 from .1001 (imagine
mantissa with radix point at its left) - need to move radix point to right one bit
- Exponent is 1 expressed in excess four notation
is 101 (How?)
Sign 0 (positive) Exponent 101 Mantissa 1001
13Storing Fractions5/6
What is the following number stored in
floating-point?
- Express number in binary to obtain 0.01 (make
sure?) - Copy bit pattern into mantissa field from left to
right starting with the leftmost 1 in binary
representation - Mantissa is 1000 (you append zeros to fill the
4-bit mantissa) - Compute exponent to get 0.01 from 0.1000
- need to move radix point to left one bit
- Exponent is -1 expressed in excess four notation
is 011 (How?)
Sign 1 (negative) Exponent 011 Mantissa 1000
14Storing Fractions6/6
What is the following number stored in
floating-point?
- Express number in binary to obtain 10.101 (make
sure?) - Copy bit pattern into mantissa field from left to
right starting with the leftmost 1 in binary
representation - Mantissa is 1010 (we run out of bits!! Rightmost
1 is lost (equivalent to 1/8)) - Compute exponent to get 10.101 from 0.1010
- need to move radix point to right two bits
- Exponent is 2 expressed in excess four notation
is 110
Sign 0 (positive) Exponent 110 Mantissa 1010
15Representing Text1/2
- ASCII (adopted by American National Standards
Institute ANSI) - American Standard Code for Information
Interchange - 8-bit to represent each symbol
- Upper and lower case letters of English alphabet,
punctuation symbols, digits 0 to 9, and other
symbols - Can represent 256 (28) different symbols
- Unicode
- 16-bit to represent each symbol
- Can represent 65,536 (216) different symbols
- ISO (International Organization for
Standardization) - 32-bit to represent each symbol
- Can represent more than 17 million symbols
16Representing Text2/2
ASCII Chart sample
- Upper case A is 6510
- Lower case a is 9710
- Difference between lower case and upper case of a
letter is always 3210
17Representing Images
- Bitmap techniques
- Image is a collection of pixels (picture element)
- Each pixel can be represented as a number of bits
(collection of bits is bitmap) - 1 bit/pixel ? B/W
- 8 bits/pixel ? Gray Scale (different shades of
gray from black to white) - 24 bits/pixel ? 1-byte for each of the primary
colors RGB - Size? (need for compression)
- Vector techniques
- Image represented as collection of lines and
curves - Fonts on printers ? scalable Fonts (True Type)
- CAD (Computer Aided Design)
- Quality problem
18Data Compression1/3
- Data compression techniques
- run-length encoding
- replace repeating sequences with a code
indicating the value being repeated and the
number of times it is repeated, e.g., aaaaa is
replaced by a5 - relative encoding
- record differences between consecutive data
blocks, e.g., consecutive frames in a motion
picture - Frequency-dependent encoding (variable length
code) - number of bits to represent an item is inversely
related to the frequency of the items use, e.g.,
(e, t, a, and i) in English would be represented
by short bit patterns, whereas (z, q, and x)
would be represented by longer patterns - Adaptive dictionary encoding
- Example is LZ77 (Lempel-Ziv)
- abaabcb (5,4,a) when decompressed is abaabcbaabca
(see Textbook page 61)
19Data Compression2/3
- Image Compression
- GIF (Graphic Interchange Format)
- 8 bits/pixel (1 byte/pixel) instead of 24
bits/pixel (3 bytes/pixel) - Each of 256 potential pixel values are associated
with a RGB combination by means of table known as
the palette - JPEG (Joint Photographic Experts Group)
- Lossless mode
- store difference between consecutive pixels
rather than pixel intensities themselves - Differences encoded using variable-length code
- Resulting bit maps not manageable with todays
technology - Base standard (lossy)
- Each pixel represented by a brightness component
and 2 color components
20Data Compression3/3
- Audio and Video compression
- MPEG (Motion Picture Experts Group)
- Start a picture sequence with an image similar to
JPEG and then represent rest of sequence using
relative encoding techniques - MP3 (MPEG-1 Audio Layer-3) audio compression
ratios of 12 to 1