- 169 Views
- Uploaded on

Download Presentation
## CS149D Elements of Computer Science

**An Image/Link below is provided (as is) to download presentation**

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

CS149D Elements of Computer Science

Ayman Abdel-Hamid

Department of Computer Science

Old Dominion University

Lecture 3: 9/3/2002

CS149D Fall 2002

Outline

- Fractions in Binary
- Storing Integers
- Sign and magnitude (covered last lecture)
- Two’s 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

CS149D Fall 2002

101.101 = (1 * 20) + (0 * 21) + (1*22) +

(1*2-1) + (0* 2-2) + (1 * 2-3)

= 1 + 4 + ½ + 1/8 =

Fractions 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

CS149D Fall 2002

Fractions 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

CS149D Fall 2002

Fractions 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

CS149D Fall 2002

Storing 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
- Two’s complement
- Advantages: deal with subtractions the same as additions, simpler hardware to perform integer arithmetic operations
- Excess Notation

CS149D Fall 2002

Storing 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?
- (2#of bits –1) = 23-1 = 4
- Smallest negative number is 000
- Largest positive number is 111

CS149D Fall 2002

Storing 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 = 3+4 = 7

Represent 7 in 3-bit binary = 111 3 in excess four is 111

CS149D Fall 2002

Storing 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)

CS149D Fall 2002

01101011 is

Storing Fractions2/6Bit 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

CS149D Fall 2002

10111100 is

Storing Fractions3/6Bit 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

CS149D Fall 2002

Storing 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

CS149D Fall 2002

Storing 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

CS149D Fall 2002

Round off error

01101010 which is really

Storing Fractions6/6What 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

CS149D Fall 2002

Representing 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

CS149D Fall 2002

Representing 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

CS149D Fall 2002

Representing 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

CS149D Fall 2002

Data 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 item’s 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)

CS149D Fall 2002

Data 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 today’s technology
- Base standard(lossy)
- Each pixel represented by a brightness component and 2 color components

CS149D Fall 2002

Data 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

CS149D Fall 2002

Download Presentation

Connecting to Server..