Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 3: Data Representation Chapter 3 Data Representation Page 17 Computers use bits to represent all types of data, including text, numerical values,

Similar presentations


Presentation on theme: "Chapter 3: Data Representation Chapter 3 Data Representation Page 17 Computers use bits to represent all types of data, including text, numerical values,"— Presentation transcript:

1

2 Chapter 3: Data Representation Chapter 3 Data Representation Page 17 Computers use bits to represent all types of data, including text, numerical values, sounds, images, and animation. How many bits does it take to represent a piece of data that could have one of, say, 1000 values? If only one bit is used, then there are only two possible values: 0 and 1. If only one bit is used, then there are only two possible values: 0 and 1. If two bits are used, then there are four possible values: 00, 01, 10, and 11. If two bits are used, then there are four possible values: 00, 01, 10, and 11. Three bits produces eight possible values: 000, 001, 010, 011, 100, 101, 110 and 111. Three bits produces eight possible values: 000, 001, 010, 011, 100, 101, 110 and 111. Four bits produces 16 values; five bits produces 32; six produces 64;... Four bits produces 16 values; five bits produces 32; six produces 64;... Continuing in this fashion, we see that k bits would produce 2 k possible values. Continuing in this fashion, we see that k bits would produce 2 k possible values. Since 2 9 is 512 and 2 10 is 1024, we would need ten bits to represent a piece of data that could have one of 1000 values. Since 2 9 is 512 and 2 10 is 1024, we would need ten bits to represent a piece of data that could have one of 1000 values. Mathematically, this is the “ceiling” of the base-two logarithm, i.e., the count of how many times you could divide by two until you get to the value one: Mathematically, this is the “ceiling” of the base-two logarithm, i.e., the count of how many times you could divide by two until you get to the value one: 1000/2=500500/2=250250/2=125125/2=6363/2=3232/2=1616/2=88/2=44/2=22/2=1 12345678910

3 Representing Integers with Bits Chapter 3 Data Representation Page 18 Two’s complement notation was established to ensure that addition between positive and negative integers shall follow the logical pattern. Examples: 4-Bit Pattern Integer Value 00000 00011 00102 00113 01004 01015 01106 01117 4-Bit Pattern Integer Value 1000-8 1001-7 1010-6 1011-5 1100-4 1101-3 1110-2 1111 11010011+ 01010101 -3 + 3 = 0 00110010+ 10110 3 + 2 = 5 11001101+ 010111 -4 + -3 = -7 01100011+ 010111 6 + 3 = -7??? OVERFLOW!10011110+ 11101 -7 + -2 = 7??? OVERFLOW!

4 Two’s Complement Coding & Decoding How do we code –44 in two’s complement notation using 8 bits? First, write the value 44 in binary using 8 bits: 00101100First, write the value 44 in binary using 8 bits: 00101100 Starting on the right side, skip over all zeros and the first one: 00101100Starting on the right side, skip over all zeros and the first one: 00101100 Continue moving left, complementing each bit: 11010100Continue moving left, complementing each bit: 11010100 The result is -44 in 8-bit two’s complement notation: 11010100The result is -44 in 8-bit two’s complement notation: 11010100 How do we decode 10110100 from two’s complement into an integer? Starting on the right side, skip over all zeros and the first one: 10110100Starting on the right side, skip over all zeros and the first one: 10110100 Continue moving left, complementing each bit: 01001100Continue moving left, complementing each bit: 01001100 Finally, convert the resulting positive bit code into an integer:76Finally, convert the resulting positive bit code into an integer:76 So, the original negative bit code must have represented:–76So, the original negative bit code must have represented:–76 Chapter 3 Data Representation Page 19

5 Representing Real Numbers with Bits When representing a real number like 17.15 in binary form, a rather complicated approach is taken.When representing a real number like 17.15 in binary form, a rather complicated approach is taken. Using only powers of two, we note that 17 is 2 4 + 2 0 and.15 is 2 -3 + 2 -6 + 2 -7 + 2 -10 + 2 -11 + 2 -14 + 2 -15 + 2 -18 + 2 -19 + 2 -22 + …Using only powers of two, we note that 17 is 2 4 + 2 0 and.15 is 2 -3 + 2 -6 + 2 -7 + 2 -10 + 2 -11 + 2 -14 + 2 -15 + 2 -18 + 2 -19 + 2 -22 + … So, in pure binary form, 17.15 would be 10001.0010011001100110011001…So, in pure binary form, 17.15 would be 10001.0010011001100110011001… In “scientific notation”, this would be 1.0001001001100110011001… × 2 4In “scientific notation”, this would be 1.0001001001100110011001… × 2 4 The standard for floating-point notation is to use 32 bits. The first bit is a sign bit (0 for positive, 1 for negative). The next eight are a bias-127 exponent (i.e., 127 + the actual exponent). And the last 23 bits are the mantissa (i.e., the exponent-less scientific notation value, without the leading 1).The standard for floating-point notation is to use 32 bits. The first bit is a sign bit (0 for positive, 1 for negative). The next eight are a bias-127 exponent (i.e., 127 + the actual exponent). And the last 23 bits are the mantissa (i.e., the exponent-less scientific notation value, without the leading 1). So, 17.15 would have the following floating-point notation:So, 17.15 would have the following floating-point notation: 0 10000011 00010010011001100110011 Chapter 3 Data Representation Page 20

6 Representing Text with Bits ASCII: American Standard Code for Information Interchange ASCII code was developed as a means of converting text into a binary notation.ASCII code was developed as a means of converting text into a binary notation. Each character has a 7-bit representation.Each character has a 7-bit representation. For example, CAT would be represented by the bits: 10000111000001 1010100For example, CAT would be represented by the bits: 10000111000001 1010100 Chapter 3 Data Representation Page 21

7 Fax Machines In order to transmit a facsimile of a document over telephone lines, fax machines were developed to essentially convert the document into a grid of tiny black and white rectangles. This important document must be faxed immediately!!! A standard 8.5  11  page is divided into 1145 rows and 1728 columns, producing approximately 2 million 0.005  0.01  rectangles. Each rectangle is scanned by the transmitting fax machine and determined to be either predominantly white or predominantly black. We could just use the binary nature of this black/white approach (e.g., 1 for black, 0 for white) to fax the document, but that would require 2 million bits per page! Chapter 3 Data Representation Page 22

8 CCITT Fax Conversion Code By using one sequence of bits to represent a long run of a single color (either black or white), the fax code can be compressed to a fraction of the two million bit code that would otherwise be needed. length white black 0 00110101 0000110111 1 000111 010 2 0111 11 3 1000 10 4 1011 011 5 1100 0011 6 1110 0010 7 1111 00011 8 10011 000101 9 10100 000100 10 00111 0000100 11 01000 0000101 12 001000 0000111 13 000011 00000100 14 110100 00000111 15 110101 000011000 16 101010 0000010111 17 101011 0000011000 18 0100111 0000001000 19 0001100 0000100111 20 0001000 00001101000 21 0010111 00001101100 22 0000011 00000110111 23 0000011 00000101000 24 0101000 00000010111 25 0101011 00000011000 26 0010011 000011001010 27 0100100 000011001011 28 0011000 000011001100 29 00000010 000011001101 30 00000011 000001101000 31 00011010 000001101001 32 00011011 000001101010 33 00010010 000001101011 34 00010011 000011010010 length white black 35 00010100 000011010011 36 00010101 000011010100 37 00010110 000011010101 38 00010111 000011010110 39 00101000 000011010111 40 00101001 000001101100 41 00101010 000001101101 42 00101011 000011011010 43 00101100 000011011011 44 00101101 000001010100 45 00000100 000001010101 46 00000101 000001010110 47 00001010 000001010111 48 00001011 000001100100 49 01010010 000001100101 50 01010011 000001010010 51 01010100 000001010011 52 01010101 000000100100 53 00100100 000000110111 54 00100101 000000111000 55 01011000 000000100111 56 01011001 000000101000 57 01011010 000001011000 58 01011011 000001011001 59 01001010 000000101011 60 01001011 000000101100 61 00110010 000001011010 62 00110011 000001100110 63 00110100 000001100111 64 11011 000000111 128 10010 000011001000 192 010111 000011001001 256 0110111 000001011011 320 00110110 000000110011 384 00110111 000000110100 length white black 448 01100100 000000110101 512 01100101 0000001101100 576 01101000 0000001101101 640 01100111 0000001001010 704 011001100 0000001001011 768 011001101 0000001001100 832 011010010 0000001001101 896 011010011 0000001110010 960 011010100 0000001110011 1024 011010101 0000001110100 1088 011010110 0000001110101 1152 011010111 0000001110110 1216 011011000 0000001110111 1280 011011001 0000001010010 1344 011011010 0000001010011 1408 011011011 0000001010100 1472 010011000 0000001010101 1536 010011001 0000001011010 1600 010011010 0000001011011 1664 011000 0000001100100 1728 010011011 0000001100101 1792 00000001000 00000001000 1856 00000001100 00000001100 1920 00000001101 00000001101 1984 000000010010 000000010010 2048 000000010011 000000010011 2112 000000010100 000000010100 2176 000000010101 000000010101 2240 000000010110 000000010110 2304 000000010111 000000010111 2368 000000011100 000000011100 2432 000000011101 000000011101 2496 000000011110 000000011110 2560 000000011111 000000011111 Chapter 3 Data Representation Page 23

9 Binary Code Interpretation Chapter 3 Data Representation Page 24 How is the following binary code interpreted? 10100111101111010000011001011100001111001111110010101110 In “programmer’s shorthand” (hexadecimal notation)… 1010011110111101000001100101110000111100 11111100 10101110 A7BD065C3C FC AE As ASCII text… 10100111101111010000011001011100001111001111110010101100 So(space)easy. As CCITT fax conversion code… 10100 9 white 11 2 black 11011 64 white 110100 14 white 00011 7 black 0010111 21 white 0000111 12 black 10011 6 white 11 2 black 1100 5 white 10 3 black 1011 4 white 10 3 black As a two’s complement integer... The negation of 01011000010000101111100110100011110000110000001101010010 (2 1 +2 4 +2 6 +2 8 +2 9 +2 16 +2 17 +2 22 +2 23 +2 24 +2 25 +2 29 +2 31 +2 32 +2 35 +2 36 +2 37 +2 38 +2 39 +2 41 +2 46 +2 51 +2 52 +2 54 ) -24,843,437,912,294,226

10 Representing Audio Data with Bits Chapter 3 Data Representation Page 25 Audio files are digitized by sampling the audio signal thousands of times per second and then “quantizing” each sample (i.e., rounding off to one of several discrete values). The ability to recreate the original analog audio depends on the resolution (i.e., the number of quantization levels used) and the sampling rate.

11 Representing Still Images with Bits Chapter 3 Data Representation Page 26 Digital images are composed of three fields of color intensity measurements, separated into a grid of thousands of pixels (picture elements). The size of the grid (the image’s resolution) determines how clear the image can be displayed. 2  2 4  4 8  8 16  16 32  32 64  64 128  128 256  256 512  512

12 RGB Color Representation Chapter 3 Data Representation Page 27 In digital display systems, each pixel in an image is represented as an additive combination of the three primary color components: red, green, and blue. TrueColor Examples RedGreenBlueResult 2551850 2550185 255125125 1852550 0255185 125255125 1850255 0185255 125125255 Printers, however, use a subtractive color system, in which the complementary colors of red, green, and blue (cyan, magenta, and yellow) are applied in inks and toners in order to subtract colors from a viewer’s perception.

13 Compressing Images with JPEG The Joint Photographic Experts Group developed an elaborate procedure for compressing color image files: First, the original image is split into 8  8 squares of pixels. Each square is split into three 8  8 grids indicating the levels of lighting and blue and red coloration the square contains. Chapter 3 Data Representation Page 28 After rounding off the values in the three grids in order to reduce the number of bits needed, each grid is traversed in a zig-zag pattern to maximize the chances that consecutive values will be equal, which, as occurred in fax machines, reduces the bit requirement even further. Depending on how severely the values were rounded, the restored image will either be a good representation of the original (with a high bit count) or a bad representation (with a low bit count).

14 Representing Video with Bits Video images are merely a sequence of still images, shown in rapid succession. Chapter 3 Data Representation Page 29 One means of compressing such a vast amount of data is to use the JPEG technique on each frame, thus exploiting each image’s spatial redundancy. The resulting image frames are called intra-frames. Video also possesses temporal redundancy, i.e., consecutive frames are usually nearly identical, with only a small percentage of the pixels changing color significantly. So video can be compressed further by periodically replacing several I-frames with predictive frames, which only contain the differences between the predictive frame and the last I-frame in the sequence. P-frames are generally about one-third the size of corresponding I-frames. The Motion Picture Experts Group (MPEG) went even further by using bidirectional frames sandwiched between I- frames and P-frames (and between consecutive P-frames). Each B-frame includes just enough information to allow the original frame to be recreated by blending the previous and next I/P-frames. B-frames are generally about half as big as the corresponding P-frames (i.e., one-sixth the size of the corresponding I-frames).


Download ppt "Chapter 3: Data Representation Chapter 3 Data Representation Page 17 Computers use bits to represent all types of data, including text, numerical values,"

Similar presentations


Ads by Google