CPSC 1050 – Lab 3 (15 marks)
Data Representation
Introduction
Computers are multimedia devices that manipulate data varying in form from numbers to graphics to video. Because a computer can manipulate only binary values, all forms of data must be represented in binary form. Data is classified as being either continuous (analog) or discrete (digital).
Integer values are represented by their binary equivalent using one of several techniques for representing negative numbers, such as a signed-magnitude or two's complement. Real numbers are represented by a triple made up of the sign, the digits in the number, and an exponent that specifies the radix point.
A character set is a list of alphanumeric and the codes that represent each character. The most commonly used character set today is Unicode (16 bits for each character), which has ASCII as a subset. The 8-bit ASCII set is sufficient for English but not for other (or multiple) languages. There are various ways for compressing text so that it takes less space to store it or less time to transmit it from one machine to another.
Audio information is represented as digitized sound waves. Color is represented by three values that represent the contribution of red, blue, and green, respectively. Two basic techniques are used for representing pictures, bitmaps, and vector graphics. Video is broken up into a series of still images, each of which is represented as a picture.
Learning Objectives
At the end of this lab, you should be able to represent:
• negative numbers in binary using signed-magnitude notation
• negative numbers in binary using two's-complement notation
• real numbers in binary
• text using the ASCII encoding methods
• colors in RGB and HSB format
• compressed text using Keyword and Huffman Encoding
Lab Readings
• Chapter 3 – Data Representation
• Lab 3 Representing Numbers (Lab3_Manual.pdf) / Negative Binary Numbers App (NegativeBinaryNumbers.jar) / Real Number Representation (RealNumberRepresentation.jar)
• Lab 4 Colorful Characters (Lab4_Manual.pdf) / Character Code App (CharacterCode.jar) / Color Maker App (ColorMaker.jar)
• Lab 5 Compressing Text (Lab5_Manual.pdf) / Keyword Text Compression (KeywordTextCompression.jar) / Huffman Text Compression App (HuffmanTextCompression.jar)
Lab Procedure
• Open "Lab 3 Representing Numbers" (Lab3_Manual.pdf), "Lab 4 Colorful Characters" (Lab4_Manual.pdf), "Lab 5 Compressing Text" (Lab5_Manual.pdf), and the related Applets.
• Review the Activity part of the labs.
• Write your answers to the following questions.
Lab Submissions
• Complete the following Lab Questions and submit to D2L by the end of the lab session.
• Complete the Lab3_Worksheet and submit to D2L by the due date.
Lab Questions
• (2 marks) Write your complete work to convert -8210 to binary using the following methods. Are your answers the same? If you convert a positive number using these methods, are the answers the same? Test your answer with "Negative Binary Numbers" Applet.
• 8-bit signed magnitude binary notation.
• 8-bit two's complement binary notation.
• (2 marks) Start the "Real Number Representation" Applet. Type a real number and read the binary equivalent at the bottom of the applet window.
• How many bits does the binary representation devote to the sign and mantissa (the part after the radix point)?
• Write your complete work to convert 62.14710 to binary. Use the same number of bits as above for mantissa.
• (2 marks) Start the "Real Number Representation" Applet. Type a number less than 1, for example 0.003672.
• What is the sign of the exponent? What is the binary equivalent of the exponent for the power of 2?
• What method has been used to convert the exponent to binary?
• (2 marks) Start the "Character Code" Applet.
• What are the Corresponding Characters for Numeric Codes of 68 and 100? What are the Corresponding Characters for Numeric Codes 70 and 102?
• If you want to write a function to capitalize text for a word-processing program, what simple transformation would you make to the Character Codes to capitalize a letter?
• (5 marks) Start the "Color Maker" Applet.
• Considering the range of values for R, G, and B, how many colors can the applet show?
• What are the values of RGB representation for Red, Green, and Blue?
• What color is the combination of Red and Blue? What are the values of RGB representation for this color?
• What color is the combination of Red and Green? What are the values of RGB representation for this color?
• What color is the combination of Green and Blue? What are the values of RGB representation for this color?
• (2 marks) Start the "Huffman Text Compression" Applet. Click on example 2 and compress.
• Remove the first bit from the beginning of the encoded message and click decompress. What happens? Do you get the original text?
• How strong is Huffman encoding to errors; i.e. if some bits are lost during the network transfer, can you still recover the original message?