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
-
Read and understand number systems.
-
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.
-
Convert the following binary numbers to decimal:
a) 101110011₂
b) 110101101₂
c) 11110110₂
-
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.
-
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? -
Convert the following hexadecimal numbers to decimal
a) AAB₁₆
b) 1FC₁₆
c) 123₁₆
-
Given the hexadecimal color value
#ff0103
a) Provide the RGB components in decimal.
b) What color is represented?
-
Convert the following binary numbers to hexadecimal
a) 10101100₂
b) 11110011₂
c) 10011001₂
-
Convert the following hexadecimal numbers to binary
a) ABC₁₆
b) D4₁₆
c) F2₁₆
-
Add the following hexadecimal numbers
a) 15CD₁₆ + 73A1₁₆
b) 234A₁₆ + BD48₁₆
-
Convert the following two’s complement binary numbers to decimal
a) 1010
b) 1110
c) 0101
-
Convert the following decimal numbers to two’s complement (4-bit)
a) –1
b) +4
c) –3
-
Given 8 bits, determine the representable value range for
a) Unsigned binary numbers
b) Signed binary numbers in two’s complement
c) Hexadecimal values
-
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.
-
Represent –3.75 in IEEE 754 single precision (32-bit).
-
Which decimal number is stored in IEEE 754 single precision (32-bit) as:
11000000011100000000000000000000
-
Explain why the following C++ code causes an overflow
unsigned char maxValue = 255; maxValue++;
-
What problems can occur if you use an
int
in C++ to store the world population? -
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;
-
Why is using floating-point numbers (float or double) for money in C++ problematic?
2.1.2 Encoding
-
Read and understand encoding.
-
What is meant by encoding, compression, and encryption? Define each term clearly and give one relevant example.
-
What is error detection and error correction?
-
Is a Hamming code linear?
-
How many errors can a Hamming code with minimum distance
d = 4
detect and correct? -
How is the Hamming distance between codewords calculated? Give an example of a code with three codewords.
-
Is the following code linear? Justify your answer:
C = {000, 001}
-
What is a prefix-free code?
-
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.
-
What is the structure of an image file?
-
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.