Chapter03 - Chapter 3: Data Representation Chapter...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Chapter 3: Data Representation Chapter Computers use bits to represent all types of data, including text, Computers all numerical values, sounds, images, and animation. numerical How many bits does it take to represent a piece of data that could have How one of, say, 1000 values? one • If only one bit is used, then there are only two possible values: 0 and 1. If one two • If two bits are used, then there are four possible values: 00, 01, 10, and If two four 11. • 11. Three bits produces eight possible values: 000, 001, 010, 011, 100, 101, eight 110 • 110 and 111. Four bits produces 16 values; five bits produces 32; six produces 16 five 32 six 6 ontinuing in this fashion, we see that k bits would produce 2k • 64; ... C4 Continuing possible • possible ivalues. 210 is 1024, we would need ten bits to represent a Since 29 s 512 and piece of data that could have one of 1000 values. piece • Mathematically, this is the “ceiling” of the base-two logarithm, i.e., the Mathematically, count of how many times you could divide by two until you get to the value one:500/2=25 250/2=12 125/2=6 63/2=3 32/2=1 16/2= 8/2=4 4/2= 2/2= v1000/2=50 alue 0 0 5 3 2 6 8 1 2 3 4 5 6 7 2 8 1 9 10 Chapter 3 Data Data Representation Representation Page 1 Page Representing Integers with Bits Representing Two’s complement notation was established to ensure that addition between positive and negative integers shall follow the logical pattern. between 4-Bit Intege 4-Bit Pattern r Pattern Value Value 4-Bit Intege 4-Bit Pattern r Pattern Value Value Examples: 11 1 +0 1 1 0 1 01 11 1 0011 +0 0 1 0 11 1100 +1 1 0 1 0000 0101 1001 0000 0 1000 -8 0001 1 1001 -7 0010 2 1010 -6 0011 3 1011 -5 0100 4 1100 -4 0101 5 1101 -3 0110 6 1110 -2 11 0110 +0 0 1 1 0111 7 1111 -1 1001 -3 + 3 = 0 3+2=5 6+3= -7??? -7??? 1 -4 + -3 = -4 -7 -7 1001 +1 1 1 0 0111 -7 + -2 = -7 7??? 7??? OVERFLOW! OVERFLOW! Chapter 3 Data Data Representation Representation Page 2 Page Two’s Complement Coding & Decoding notation using 8 bits? D in two’s complement How do we code –44 ecoding • First, write the value 44 in binary using 8 bits: 00101100 • Starting on the right side, skip over all zeros and the first one: Starting right first 00101100 • Continue moving left, complementing each bit: Continue each 11010100 How do we decode 10110100 from two’s complement into an integer? How 10110100 • The result is -44 in 8-bit two’s complement notation: • Starting on the right side, skip over all zeros and the first one: Starting right first 11010100 10110100 10110 • Continue moving left, complementing each bit: Continue each 01001100 01001 • Finally, convert the resulting positive bit code into an integer: • So, the original negative bit code must have represented: –76 76 Chapter 3 Data Data Representation Representation Page 3 Page Representing Real Numbers with • When representingits number like 17.15 in binary form, a rather When Bitsis taken. B a real complicated approach complicated 3 6 • Using only powers of two, we note that 17 is 24 + 20 and .15 is 2--3 + 2--6 + 7 10 11 14 15 18 19 22 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 So, 10001.0010011001100110011001… 10001.0010011001100110011001… • In “scientific notation”, this would be 1.0001001001100110011001… × In 24 • The standard for floating-point notation is to use 32 bits. The first bit The is a sign bit (0 for positive, 1 for negative). The next eight are a biassign bias127 exponent (i.e., 127 + the actual exponent). And the last 23 bits are 127 the mantissa (i.e., the exponent-less scientific notation value, without mantissa the leading 1). the 0 10000011 00010010011001100110011 • So, 17.15 would have the following floating-point notation: Chapter 3 Data Data Representation Representation Page 4 Page Representing Text with Bits Representing • ASCII: ASCII: American Standard Code for I SCII Anformation ASCII code was Interchange Interchange developed as a means of converting text into a binary notation. notation. • Each Each character has a 7-bit representatio representatio n. • For example, For CAT would be represented Chapter 3 Data Data Representation Representation by the bits: Page 5 Page 100001110000 100001110000 Fax Machines Fax In order to transmit a facsimile of a document over telephone In lines, fax machines were developed to essentially convert the fax document into a grid of tiny black and white rectangles. document 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. 0.005 Each rectangle is scanned by the Each transmitting fax machine and determined to be either predominantly white or predominantly black. predominantly We could just use the binary We 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! per Chapter 3 Data Data Representation Representation Page 6 Page CCITT Fax Conversion Code CCITT length length 0 1 2 3 4 5 6 7 8 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 white white 00110101 00110101 000111 000111 0111 0111 1000 1000 1011 1011 1100 1100 1110 1110 1111 1111 10011 10011 10100 10100 00111 00111 01000 01000 001000 001000 000011 000011 110100 110100 110101 110101 101010 101010 101011 101011 0100111 0100111 0001100 0001100 0001000 0001000 0010111 0010111 0000011 0000011 0000011 0000011 0101000 0101000 0101011 0101011 0010011 0010011 0100100 0100100 0011000 0011000 00000010 00000010 00000011 00000011 00011010 00011010 00011011 00011011 00010010 00010010 00010011 00010011 black black 0000110111 0000110111 010 010 11 11 10 10 011 011 0011 0011 0010 0010 00011 00011 000101 000101 000100 000100 0000100 0000100 0000101 0000101 0000111 0000111 00000100 00000100 00000111 00000111 000011000 000011000 0000010111 0000010111 0000011000 0000011000 0000001000 0000001000 0000100111 0000100111 00001101000 00001101000 00001101100 00001101100 00000110111 00000110111 00000101000 00000101000 00000010111 00000010111 00000011000 00000011000 000011001010 000011001010 000011001011 000011001011 000011001100 000011001100 000011001101 000011001101 000001101000 000001101000 000001101001 000001101001 000001101010 000001101010 000001101011 000001101011 000011010010 000011010010 length length 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 53 53 54 54 55 55 56 56 57 57 58 58 59 59 60 60 61 61 62 62 63 64 64 128 128 192 192 256 256 320 320 384 384 white white 00010100 00010100 00010101 00010101 00010110 00010110 00010111 00010111 00101000 00101000 00101001 00101001 00101010 00101010 00101011 00101011 00101100 00101100 00101101 00101101 00000100 00000100 00000101 00000101 00001010 00001010 00001011 00001011 01010010 01010010 01010011 01010011 01010100 01010100 01010101 01010101 00100100 00100100 00100101 00100101 01011000 01011000 01011001 01011001 01011010 01011010 01011011 01011011 01001010 01001010 01001011 01001011 00110010 00110010 00110011 00110011 00110100 11011 11011 10010 10010 010111 010111 0110111 0110111 00110110 00110110 00110111 00110111 black black 000011010011 000011010011 000011010100 000011010100 000011010101 000011010101 000011010110 000011010110 000011010111 000011010111 000001101100 000001101100 000001101101 000001101101 000011011010 000011011010 000011011011 000011011011 000001010100 000001010100 000001010101 000001010101 000001010110 000001010110 000001010111 000001010111 000001100100 000001100100 000001100101 000001100101 000001010010 000001010010 000001010011 000001010011 000000100100 000000100100 000000110111 000000110111 000000111000 000000111000 000000100111 000000100111 000000101000 000000101000 000001011000 000001011000 000001011001 000001011001 000000101011 000000101011 000000101100 000000101100 000001011010 000001011010 000001100110 000001100110 000001100111 000001100111 000000111 000000111 000011001000 000011001000 000011001001 000011001001 000001011011 000001011011 000000110011 000000110011 000000110100 000000110100 length length 448 448 512 512 576 576 640 640 704 704 768 768 832 832 896 896 960 960 1024 1024 1088 1088 1152 1152 1216 1216 1280 1280 1344 1344 1408 1408 1472 1472 1536 1536 1600 1600 1664 1664 1728 1728 1792 1792 1856 1856 1920 1920 1984 2048 2048 2112 2112 2176 2176 2240 2240 2304 2304 2368 2368 2432 2432 2496 2496 2560 2560 white white 01100100 01100100 01100101 01100101 01101000 01100111 011001100 011001100 011001101 011001101 011010010 011010010 011010011 011010011 011010100 011010100 011010101 011010101 011010110 011010110 011010111 011011000 011011000 011011001 011011010 011011010 011011011 010011000 010011001 010011010 011000 011000 010011011 00000001000 00000001100 00000001100 00000001101 000000010010 000000010010 000000010011 000000010011 000000010100 000000010100 000000010101 000000010101 000000010110 000000010110 000000010111 000000010111 000000011100 000000011100 000000011101 000000011101 000000011110 000000011110 000000011111 000000011111 black black 000000110101 000000110101 0000001101100 0000001101100 0000001101101 0000001101101 0000001001010 0000001001010 0000001001011 0000001001011 0000001001100 0000001001100 0000001001101 0000001001101 0000001110010 0000001110010 0000001110011 0000001110011 0000001110100 0000001110100 0000001110101 0000001110101 0000001110110 0000001110110 0000001110111 0000001110111 0000001010010 0000001010010 0000001010011 0000001010011 0000001010100 0000001010100 0000001010101 0000001010101 0000001011010 0000001011010 0000001011011 0000001011011 0000001100100 0000001100100 0000001100101 0000001100101 00000001000 00000001000 00000001100 00000001100 00000001101 00000001101 000000010010 000000010010 000000010011 000000010011 000000010100 000000010100 000000010101 000000010101 000000010110 000000010110 000000010111 000000010111 000000011100 000000011100 000000011101 000000011101 000000011110 000000011110 000000011111 000000011111 By using By one sequence of bits to represent a long run of a single color (either black or white), the fax code can be compresse compresse d to a fraction of the two million bit code that would otherwise be needed. be Chapter 3 Data Data Representation Representation Page 7 Page Binary Code Interpretation Binary How is the following binary code interpreted? 10100111101111010000011001011100001111001111110010101110 In “programmer’s shorthand” (hexadecimal notation)… 1010 0111 1011 1101 0000 0110 0101 1100 0011 1100 1111 1100 1010 1110 A 7 B D 0 6 5 C 3 C F C A E As a two’s complement integer... The negation of The 01011000010000101111100110100011110000110000001101010010 01011000010000101111100110100011110000110000001101010010 (21+24+26+28+29+216+217+222+223+224+225+229+231+232+235+236+237+238+239+241+246+251+252 -24,843,437,912,294,226 +254) As ASCII text… 1010011 1101111 0100000 1100101 1100001 1110011 1111001 0101100 S o (space) e a s y . As CCITT fax conversion code… 10 10 00011 0000111 11 10100 11011 11010 0010111 10011 1100 3 1011 3 2 7 black 12 black 2 black black 0 9 white black 64 white 21 white 6 white black 5 white black 4 black black black 11 14 white white white Chapter 3 Data Data Representation Representation Page 8 Page Representing Audio Data with Bits Representing Audio files are digitized by sampling the audio signal Audio thousands of times per second and then “quantizing” each sample (i.e., rounding off to one of several discrete values). values). The ability to recreate the original analog The audio depends on the resolution (i.e., the number of quantization levels used) and the Chapter 3 Data Data Representation Representation Page 9 Page Representing Still Images with Bits Representing Digital images are composed Digital of three fields of color intensity measurements, separated into a grid of thousands of pixels (picture elements) . elements) The size of the grid (the The image’s resolution) resolution determines how clear the image can be displayed. image 128 × 26 538 84 212 42 56 5 66 12 4 128 128 512 656 256 312 32 64 16 Chapter 3 Data Data Representation Representation Page 10 Page 10 RGB Color Representation RGB In digital display systems, each pixel in an In image is represented as an additive additive combination of the three primary color components: red, green, and blue. components: TrueColor Examples Red Gree n Blue 255 185 0 255 0 185 255 125 125 185 255 0 0 255 185 125 255 125 185 0 255 0 185 255 125 125 255 Result Printers, however, use a Printers, subtractive color subtractive 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 subtract viewer’s perception. viewer’s Chapter 3 Data Data Representation Representation Page 11 Page 11 Compressing Images with JPEG Compressing The Joint Photographic Experts Group developed an The elaborate procedure for compressing color image files: the original files: Each square is split into three 8× 8 grids grids First, First, image is split into 8× 8 squares of squares pixels. pixels. After rounding off the values After 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 indicating the levels of lighting and blue and red coloration the square contains. and 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). representation Chapter 3 Data Data Representation Representation Page 12 Page 12 Representing Video with Bits Representing Video images are merely a sequence of still images, shown in rapid Video succession. succession. One means of compressing such a One vast amount of data is to use the JPEG technique on each frame, thus exploiting each image’s spatial redundancy. The resulting image redundancy The frames are called intra-frames. intra-frames Video also possesses temporal redundancy, i.e., Video temporal 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 predictive which only contain the differences between the predictive frame differences and the last I-frame in the sequence. P-frames are generally about one-third the size of corresponding I-frames. about The Motion Picture Experts Group (MPEG) went even The further by using bidirectional frames sandwiched bidirectional 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/Precreated frames. B-frames are generally about half as big as frames. the corresponding P-frames (i.e., one-sixth the size of the corresponding I-frames). the Chapter 3 Data Data Representation Representation Page 13 Page 13 ...
View Full Document

Ask a homework question - tutors are online