Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing...
-
Upload
grant-neal -
Category
Documents
-
view
216 -
download
2
Transcript of Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing...
![Page 1: Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.](https://reader036.fdocuments.in/reader036/viewer/2022082712/56649e185503460f94b05006/html5/thumbnails/1.jpg)
Lecture 5
![Page 2: Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.](https://reader036.fdocuments.in/reader036/viewer/2022082712/56649e185503460f94b05006/html5/thumbnails/2.jpg)
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
![Page 3: Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.](https://reader036.fdocuments.in/reader036/viewer/2022082712/56649e185503460f94b05006/html5/thumbnails/3.jpg)
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
![Page 4: Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.](https://reader036.fdocuments.in/reader036/viewer/2022082712/56649e185503460f94b05006/html5/thumbnails/4.jpg)
![Page 5: Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.](https://reader036.fdocuments.in/reader036/viewer/2022082712/56649e185503460f94b05006/html5/thumbnails/5.jpg)
Figure 1.12 The message “Hello.” in ASCII
![Page 6: Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.](https://reader036.fdocuments.in/reader036/viewer/2022082712/56649e185503460f94b05006/html5/thumbnails/6.jpg)
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
![Page 7: Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.](https://reader036.fdocuments.in/reader036/viewer/2022082712/56649e185503460f94b05006/html5/thumbnails/7.jpg)
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 patternResolution 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
![Page 8: Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.](https://reader036.fdocuments.in/reader036/viewer/2022082712/56649e185503460f94b05006/html5/thumbnails/8.jpg)
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
![Page 9: Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.](https://reader036.fdocuments.in/reader036/viewer/2022082712/56649e185503460f94b05006/html5/thumbnails/9.jpg)
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)
Binary(7-bit magnitude)
+17 010001 00010001
-17 110001 10010001
Problems• “0000” = “1000” !• How to add and subtract? Can’t just handle each digit at a time…
![Page 10: Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.](https://reader036.fdocuments.in/reader036/viewer/2022082712/56649e185503460f94b05006/html5/thumbnails/10.jpg)
Attempt #2: One’s complement To negate, invert all bits.
Decimal Binary3-bit mag.
Decimal Binary3-bit mag.
0 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.
![Page 11: Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.](https://reader036.fdocuments.in/reader036/viewer/2022082712/56649e185503460f94b05006/html5/thumbnails/11.jpg)
Attempt #3: Two’s complement Invert all bits, then add 1.
Decimal Binary3-bit mag.
Decimal Binary3-bit mag.
0 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…
![Page 12: Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.](https://reader036.fdocuments.in/reader036/viewer/2022082712/56649e185503460f94b05006/html5/thumbnails/12.jpg)
Two’s complement – it just works! 0011 (3 decimal)
+ 0010 (2 decimal)
= (5 decimal ?)
1101 (-3 decimal)
+ 1110 (-2 decimal)
= (-5 decimal ?)
0011 (3 decimal)
+ 1110 (-2 decimal)
= (1 decimal ?)
0101
11011
10001
![Page 13: Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.](https://reader036.fdocuments.in/reader036/viewer/2022082712/56649e185503460f94b05006/html5/thumbnails/13.jpg)
Problems with binary arithmetic Fixed number of bits can go out of
range.
0011 (3 decimal)
+ 0111 (7 decimal)
= 1010 (-6 decimal???)
Overflow: When result can’t be represented within range of bits.
In addition, if operands have same sign and sum doesn’t.
![Page 14: Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.](https://reader036.fdocuments.in/reader036/viewer/2022082712/56649e185503460f94b05006/html5/thumbnails/14.jpg)
Summary
Representations Binary Hexadecimal
Values Unsigned Two’s complement
0000 0001
0010
0011
0100
0101
0110
011110001001
1011
1100
1101
1010
1110
1111
01
2
3
4
5
6
789
A
D
C
B
E
F
0 1
2
3
4
5
6789
10
11
12
13
14
15
0 1
-8
3
4
5
67
2
-7-6
-5
-4
-3-2
-1