lab_2_worksheet

docx

School

Langara College *

*We aren’t endorsed by this school

Course

1050

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

4

Uploaded by GrandGuineaPig4093

Report
Lab 2: Chapter 3, Data Representation — Negative Integers, Non- negative Floating Point Numbers (Fractions), Text, Text Compression. [52 marks] In all of the problems, you must show your work to qualify for the mark. Type your answer in this worksheet after each question. Export the completed worksheet to PDF and Submit the PDF version with D2L. The related Lab Manual PDF files and Applets are included on D2L. It is recommended that you read the PDF Files and try some examples with the Applets. 1. [3 marks] Convert -45 to 8-bit signed magnitude binary notation. Check your answer with "Negative Binary Numbers" Applet. Answer: -45= 10101101 2 2. [4 marks] Convert -45 to 8-bit 2's complement binary notation. Check your answer with "Negative Binary Numbers" Applet. Answer: -45 = 45 = 00101101 = 11010010+1 = 11010011 2 3. [9 marks] Convert the following 8-bit signed magnitude binary numbers to decimal. 10101010 00101010=42=-42 00110101 00110101=53 11110100 01110100=116=-116 Page 1
4. [9 marks] Convert the following 8-bit 2's complement binary numbers to decimal. Note: A non-negative number’s 2’s complement is the same as its sign-magnitude. 10101110 01010001+1=01010010= 82= -82 00110101 11001010+1=11001011= -75= 75 11101010 00010101+1=00010110=22=-22 5. [ 2] Convert ˗137 to Binary using "Negative Binary Numbers" Applet. How many Bits would be needed and Why? So when we use 8-bits to represent -137 in binary, the case of overflow occurs as the value does not fit into the number of bits we have allocated for the result. Therefore, in order to represent -137, we need 9 bits because it can represent numbers from -256(2 (9-1) ) to +256(2 (9-1) ). Page 2
6. [5 marks] Convert the decimal 27.137 to binary. Stop after 5 binary digits to the right of the decimal point. We divide 27 with 2 and we multiply the decimal part (0.137) with 2 0.137*2= 0 +0.274 0.274*2= 0 +0.584 0.584*2= 1 +0.096 0.096*2= 0 +0.192 0.192*2= 0 +0.384 27.137 10 =11011.00100 2 7. [5 marks] Convert the binary 1111.0011 to a decimal number (with fraction). Show the full polynomial first. Answer: 1111.0011 2 = 1*2 3 +1*2 2 +1*2 1 +1*2 0 +0*2 -1 +0*2 -2 +1*2 -3 +1*2 -4 = 8+4+2+1+0.125+0.0625 = 15.1875 10 8. [4 marks] Write your first and last names. What will your name be in ASCII codes. Use hexadecimal. Note that you will need an ASCII table. Answer: Manvir Singh = 4D 61 6E 76 69 72 20 53 69 6E 67 68 9. [3 marks] Decode the following ASCII coded phrase. These are the decimal numbers for each ASCII character. Note that you will need an ASCII table. 67 111 110 118 101 114 116 105 110 103 32 102 114 111 109 32 65 83 67 73 73 32 99 111 100 101 115 32 116 111 32 116 101 120 116 32 105 115 32 102 117 110 46 32 40 78 79 84 33 41 Answer: Converting from ASCII codes to text is fun. (NOT!) 10. [8] Given the Huffman Encoding table, decode the following bit strings. In each case, calculate Page 3 27/2 1 13/2 1 6/2 0 3/2 1 1/2 1 0
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
the compression ratio if we normally use the 8-bit ASCII code for characters. a. 11 0111 00 010 11 – ELATE The Compression ratio is: Encoded Text/ Original Text 5/13=0.38 b. 0110 101010 10010 1011 11 1000 CHORES Compression Ratio=6/25=0.24 c. 101001 00 101000 010 00 1000 010 10011 0110 FANTASTIC Compression Ratio= 9/35=0.26 d. 101000 10010 101000 1000 11 101000 1000 11 NONSENSE Compression Ratio= 8/35=0.23 Page 4 HUFFMAN CODE CHARACTER 00 A 11 E 010 T 0110 C 0111 L 1000 S 1011 R 10010 O 10011 I 101000 N 101001 F 101010 H 101011 D