generated from mwc/lab_encoding
completes the questions in questions.md for the encoding lab
This commit is contained in:
22
questions.md
22
questions.md
@@ -20,17 +20,24 @@ The answers to the first two questions are given.
|
||||
~a & ~b
|
||||
|
||||
3. 00000001
|
||||
~a & b
|
||||
|
||||
4. 10000000
|
||||
a & (b ^ b)
|
||||
|
||||
5. 01010000
|
||||
a & ~b
|
||||
|
||||
6. 00001010
|
||||
~a & b
|
||||
|
||||
7. 01010000
|
||||
a & ~b
|
||||
|
||||
8. 10101011
|
||||
|
||||
b | (~a & ~b)
|
||||
|
||||
## Integer questions
|
||||
|
||||
These questions are difficult! Try exploring ideas with `Bits`
|
||||
@@ -40,9 +47,13 @@ talk with others.
|
||||
9. If `a` represents a positive integer, and `one = Bits(1, length=len(a))`,
|
||||
give an expression equivalent to `-a`, but which does not use negation.
|
||||
|
||||
~a + one
|
||||
|
||||
10. It is extremely easy to double a binary number: just shift all the bits
|
||||
to the left. (`a << 1` is twice `a`.) Explain why this trick works.
|
||||
|
||||
Every bit position represents a power of 2. Shifting all bits one place to the left multiplies every bit's value by 2.
|
||||
|
||||
11. Consider the following:
|
||||
```
|
||||
>>> hundred = Bits(100, 8)
|
||||
@@ -55,16 +66,25 @@ talk with others.
|
||||
```
|
||||
Apparently 100 + 100 = -56. What's going on here?
|
||||
|
||||
100 + 100 = 200 in bit it is 11001000. Because the first is 1 the bit represents a negative number -56.
|
||||
|
||||
12. What is the bit representation of negative zero? Explain your answer.
|
||||
|
||||
There is no negative zero zero is only represented by 00000000.
|
||||
|
||||
13. What's the largest integer that can be represented in a single byte?
|
||||
Explain your reasoning.
|
||||
|
||||
127 is the largest because the first 1 represents a negative hence 01111111 = 127
|
||||
|
||||
14. What's the smallest integer that can be represented in a single byte?
|
||||
Explain your reasoning.
|
||||
|
||||
-128 is the smallest where the smallest is 10000000.
|
||||
|
||||
15. What's the largest integer that can be represented in `n` bits?
|
||||
Explain your reasoning.
|
||||
2^(n-1) -1 : one bit is used for the sign example if n = 3 bits then it would be 2^2 - 1 = 3 leading to 011.
|
||||
|
||||
## Text questions
|
||||
|
||||
@@ -90,4 +110,6 @@ talk with others.
|
||||
|
||||
Make a hypothesis about how this could work.
|
||||
|
||||
Use the leading bits of the first byte to indicate the total length of the characters where 0--------- = 1 byte "a" then 110------- = 2 byte "n" characters, 1110------ = 3 byte, shade characters then each byte has specific meaning as used above.
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user