From e0db178d7d7e261610d33442ae41a1a1e4a51ba7 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Tue, 14 Jul 2026 18:13:18 +0100 Subject: [PATCH 1/3] part_1 --- number-systems/Part-1.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/number-systems/Part-1.md b/number-systems/Part-1.md index d8f9c290e..1ae853c20 100644 --- a/number-systems/Part-1.md +++ b/number-systems/Part-1.md @@ -7,48 +7,48 @@ The goal of these exercises is for you to gain an intuition for binary numbers. The answers to these questions should be a number, either in binary, hex, or decimal. Q1: Convert the decimal number 14 to binary. -Answer: +Answer: 1110 Q2: Convert the binary number 101101 to decimal: -Answer: +Answer: 45 Q3: Which is larger: 1000 or 0111? -Answer: +Answer: 1000 Q4: Which is larger: 00100 or 01011? -Answer: +Answer: 01011 Q5: What is 10101 + 01010? -Answer: +Answer: 11111 Q6: What is 10001 + 10001? -Answer: +Answer: 100010 Q7: What's the largest number you can store with 4 bits, if you want to be able to represent the number 0? -Answer: +Answer: 15 Q8: How many bits would you need in order to store the numbers between 0 and 255 inclusive? Answer: Q9: How many bits would you need in order to store the numbers between 0 and 3 inclusive? -Answer: +Answer: 2 Q10: How many bits would you need in order to store the numbers between 0 and 1000 inclusive? -Answer: +Answer: 10 Q11: Convert the decimal number 14 to hex. -Answer: - +Answer: E + Q12: Convert the decimal number 386 to hex. -Answer: +Answer: 182 Q13: Convert the hex number 386 to decimal. -Answer: +Answer: 902 Q14: Convert the hex number B to decimal. -Answer: +Answer: 11 Q15: If reading the byte 0x21 as a number, what decimal number would it mean? -Answer: +Answer: 33 Q16: Continues in Part-2 From 4d349d6c7b201c950409c8a4f1a1605c58d31a2a Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Tue, 14 Jul 2026 19:58:44 +0100 Subject: [PATCH 2/3] part2 --- number-systems/Part-2.md | 47 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/number-systems/Part-2.md b/number-systems/Part-2.md index 68b0933d9..77c8979e2 100644 --- a/number-systems/Part-2.md +++ b/number-systems/Part-2.md @@ -9,14 +9,55 @@ The answers to these questions will require a bit of explanation, not just a sim Q16: How can you test if a binary number is a power of two (e.g. 1, 2, 4, 8, 16, ...)? Answer: +A power of two has exactly one bit set (e.g. 1000 or 0100 — leading zeros +don't count). E.g. 0100 is 2^2 but 0110 is 2^2 + 2^1. + +One method to figure this out is to repeatedly divide the number by 2: + +Since 0 has no bits set and the power of 2 is always positive these are not checked. So, for any n > 0 , repeatedly right-shift n, which is equivalent to dividing by 2. +The bit dropped off by each shift is the remainder: if it's ever 1, n is not a +power of two. If you shift all the way down to a single remaining bit — the +original number's leading 1 — without ever dropping a 1, then n is a power of two. + +Another, more efficient method is to check the bitwise AND of n with (n-1). + +For example: + +``` +n = 1000 +n-1 = 0111 + +n & (n - 1): +1000 +0111 +---- +0000 +``` + +If the result is 0000 then it is a power of two only if the result is 0. + Q17: If reading the byte 0x21 as an ASCII character, what character would it mean? -Answer: +Answer: ! -Q18: If reading the byte 0x21 as a greyscale colour, as described in "Approaches for Representing Colors and Images", what colour would it mean? -Answer: +Q18: If reading the byte 0x21 as a greyscale colour, as described in "Approaches for Representing Colors and Images", what colour would it mean? Answer: +Figure 2.2 illustrates 4 shades of gray, 0x00 = black, 0x55 = dark gray, 0xAA = light gray, and 0xFF = white. As 0x21 falls between black and dark gray, it would be classified as dark gray or very dark gray. Q19: If reading the bytes 0xAA00FF as a sequence of three one-byte decimal numbers, what decimal numbers would they be? Answer: +``` +AA = 10 * 16^1 + 10 * 16^0 = 170 +00 = 0 +FF = 0b11111111 = 2^8-1 = 255 +``` + Q20: If reading the bytes 0xAA00FF as an RGB colour, as described in "Approaches for Representing Colors and Images", what colour would it mean? Answer: + +Red: 170 + +Green: 0 + +Blue: 255 + +A lot of blue and red = purple From 5d9ad27e19af1dd9d7b980cd88010ceb8b3adfe0 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Tue, 14 Jul 2026 20:53:16 +0100 Subject: [PATCH 3/3] q8 --- number-systems/Part-1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/number-systems/Part-1.md b/number-systems/Part-1.md index 1ae853c20..a2d4ef1bc 100644 --- a/number-systems/Part-1.md +++ b/number-systems/Part-1.md @@ -28,7 +28,7 @@ Q7: What's the largest number you can store with 4 bits, if you want to be able Answer: 15 Q8: How many bits would you need in order to store the numbers between 0 and 255 inclusive? -Answer: +Answer: 8 Q9: How many bits would you need in order to store the numbers between 0 and 3 inclusive? Answer: 2