Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 5.

Similar presentations


Presentation on theme: "Lecture 5."— Presentation transcript:

1 Lecture 5

2 Topics Sec 1.4 Representing Information as Bit Patterns
Representing Text Representing Numeric Values Representing Images Sec 1.6 Storing Integers Two’s Complement Notation Excess Notation

3 Representing Text Each character (letter, punctuation, etc.) is assigned a unique bit pattern. ASCII: Uses patterns of 7-bits to represent most symbols used in written English text Unicode: Uses patterns of 16-bits to represent the major symbols used in languages world side ISO standard: Uses patterns of 32-bits to represent most symbols used in languages world wide

4

5 Figure 1.12 The message “Hello.” in ASCII

6 Representing Numeric Values
Binary notation: Uses bits to represent a number in base two Limitations of computer representations of numeric values Overflow – occurs when a value is too big to be represented Truncation – occurs when a value cannot be represented accurately

7 Representing Images Images are stored using a variety of formats and compression techniques The simplest representation is a bitmap Bitmaps partition an image into a grid of picture elements, called pixels, and then convert each pixel into a bit pattern Resolution refers to the sharpness or clarity of an image bitmaps that are divided into smaller pixels will yield higher resolution images the left image is stored using 96 pixels per square inch, and the right image is stored using 48 pixels per square inch the left image appears sharp, but has twice the storage requirements

8 What about “negative seventeen”?
Can use “+” and “-”, as usual. But requires extra symbols. How can we use bits instead? Decimal Binary +17 +10001 -17 -10001

9 Attempt #1: Sign & magnitude
Fix the #bits used to represent the magnitude. Q: What is the range of “n” bits? Replace “+” with “0”, and “-” with “1”. Decimal Binary (5-bit magnitude) (7-bit magnitude) +17 010001 -17 110001 Problems “0000” = “1000” ! How to add and subtract? Can’t just handle each digit at a time…

10 Attempt #2: One’s complement
To negate, invert all bits. Decimal Binary 3-bit mag. 0000 -0 1111 1 0001 -1 1110 2 0010 -2 1101 3 0011 -3 1100 4 0100 -4 1011 5 0101 -5 1010 6 0110 -6 1001 7 0111 -7 1000 Still same problems – ambiguous zero, can’t add/subtract one bit at a time.

11 Attempt #3: Two’s complement
Invert all bits, then add 1. Decimal Binary 3-bit mag. 0000 1 0001 -1 1111 2 0010 -2 1110 3 0011 -3 1101 4 0100 -4 1100 5 0101 -5 1011 6 0110 -6 1010 7 0111 -7 1001 -8 1000 No ambiguous zero. Adding and subtracting work nicely…

12 Two’s complement – it just works!
0011 (3 decimal) (2 decimal) = (5 decimal ?) 0101 1101 (-3 decimal) (-2 decimal) = (-5 decimal ?) 11011 0011 (3 decimal) (-2 decimal) = (1 decimal ?) 10001

13 Problems with binary arithmetic
Fixed number of bits  can go out of range. (3 decimal) (7 decimal) = (-6 decimal???) Overflow: When result can’t be represented within range of bits. In addition, if operands have same sign and sum doesn’t.

14 Summary Representations Values Binary Hexadecimal Unsigned
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1011 1100 1101 1010 1110 1111 1 2 3 4 5 6 7 8 9 A D C B E F 10 11 12 13 14 15 -8 -7 -6 -5 -4 -3 -2 -1 Representations Binary Hexadecimal Values Unsigned Two’s complement


Download ppt "Lecture 5."

Similar presentations


Ads by Google