Skip to content

2. Lab 2: Number Formats & Encoding

In this lab, you will understand number systems and encoding. Number formats like binary and hexadecimal allow efficient data processing, storage, and interpretation. Encoding is the foundation of representing information such as text, images, or audio in a digital format.

2.1 Preparation

Please complete this section preparation before your lab. Use the lectures to discuss any questions you have.

2.1.1 Number Systems

  1. Read and understand number systems.

  2. Explain the meaning and use of the binary and hexadecimal systems in computer science. Address the following points

    • The fundamental role of binary in digital data processing
    • Advantages of hexadecimal over binary
    • Practical use cases for hexadecimal numbers in computer science
    • Efficiency benefits of using hexadecimal

    Structure your answer clearly and include examples where helpful.

  3. Convert the following binary numbers to decimal:

    a) 101110011₂

    b) 110101101₂

    c) 11110110₂

  4. Given the 8-bit binary number 11010110:

    a) Perform a left shift by 2 positions. What is the result in binary and decimal?

    b) Perform a right shift by 3 positions. What is the result in binary and decimal?

    c) Briefly explain how a one-position left shift affects the decimal value.

  5. In computer graphics, bit shifts are used to manipulate color values. Given a 24-bit color: 11110000 10101010 00001111, which bit shift operation(s) would you use to extract the green value?

  6. Convert the following hexadecimal numbers to decimal

    a) AAB₁₆

    b) 1FC₁₆

    c) 123₁₆

  7. Given the hexadecimal color value #ff0103

    a) Provide the RGB components in decimal.

    b) What color is represented?

  8. Convert the following binary numbers to hexadecimal

    a) 10101100₂

    b) 11110011₂

    c) 10011001₂

  9. Convert the following hexadecimal numbers to binary

    a) ABC₁₆

    b) D4₁₆

    c) F2₁₆

  10. Add the following hexadecimal numbers

    a) 15CD₁₆ + 73A1₁₆

    b) 234A₁₆ + BD48₁₆

  11. Convert the following two’s complement binary numbers to decimal

    a) 1010

    b) 1110

    c) 0101

  12. Convert the following decimal numbers to two’s complement (4-bit)

    a) –1

    b) +4

    c) –3

  13. Given 8 bits, determine the representable value range for

    a) Unsigned binary numbers

    b) Signed binary numbers in two’s complement

    c) Hexadecimal values

  14. How many bits are required to represent the following ranges?

    a) Decimal values from 0 to 1000 in unsigned binary

    b) Integer values from –500 to +500 in two’s complement

    c) Hexadecimal values from 00 to FF

    Justify your answers briefly and provide the formula used.

  15. Represent –3.75 in IEEE 754 single precision (32-bit).

  16. Which decimal number is stored in IEEE 754 single precision (32-bit) as: 11000000011100000000000000000000

  17. Explain why the following C++ code causes an overflow

    unsigned char maxValue = 255;
    maxValue++;
    
  18. What problems can occur if you use an int in C++ to store the world population?

  19. Explain why this C++ code doesn’t return the expected result

    double result = 0.1 + 0.2;
    bool ok = false;
    if (result == 0.3) ok = true;
    
  20. Why is using floating-point numbers (float or double) for money in C++ problematic?

2.1.2 Encoding

  1. Read and understand encoding.

  2. What is meant by encoding, compression, and encryption? Define each term clearly and give one relevant example.

  3. What is error detection and error correction?

  4. Is a Hamming code linear?

  5. How many errors can a Hamming code with minimum distance d = 4 detect and correct?

  6. How is the Hamming distance between codewords calculated? Give an example of a code with three codewords.

  7. Is the following code linear? Justify your answer: C = {000, 001}

  8. What is a prefix-free code?

  9. Describe how to construct a Huffman tree in your own words. And do so with any word of 5-10 characters. Encode and decode your word.

  10. What is the structure of an image file?

  11. What is a codec?

2.2 During the Lab

  • We will address any questions you have.
  • You will present selected tasks.

2.3 After the lab

Prepare the next lab.