I completed the questions and the predictions

based on the information given in the lab.

This process was fun and puzzling. I think that when teaching this it would
be cool to do so in puzzles. Giving students these bytes and asking them to,
like we did, just make predictions and then break them down together.

There are times with binary in this lab that were a struggle, but I really
enjoyed working through them and meeting with Stacy to discuss the questions and
challenges!
This commit is contained in:
Rebecca Hankey 2025-02-23 09:58:31 -05:00
parent 3b669a7f10
commit 8e7bd7938c
1 changed files with 40 additions and 0 deletions

View File

@ -52,9 +52,18 @@ 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.
The way I envision this trick is similar to when you mutiply something by 10. You
simply add a zero to the end of the number and that is the answer because it moves the entire a space
to the left, therefore moving it's tens position. With the same idea, (using the examples from the lab)
Bits(4, length = 8) which is 00000100. Then Bits(8, length = 8) wld become 000010000 because the zero is
added at the end, one is dropped from the beginning. Then the byte is doubled because the entire "number"
now reads as being moved up one space.
11. Consider the following:
```
>>> hundred = Bits(100, 8)
@ -67,16 +76,36 @@ talk with others.
```
Apparently 100 + 100 = -56. What's going on here?
>>> hundred = Bits(100, 8)
>>> hundred
01100100
This first section indicates that there is a byte that is 8 bits long that stands for hundred.
This would be 01100100. When you add (hunderd to hunderd) in the following line, it works like the question
before where the number is doubled and changes accordingly.
Therefore, (hundred + hundred) is 11001000 (as indicated in line 73). Then we have the weird lines.
>>> (hundred + hundred).int
-56
Adding .int to the end of the equation changes what the numbers stand for. If we take the byte 11001000, the '1' means that the number it stands for will be negative. By adding the two together it runs over the 8 bit integer that is defined by the first line. >>> hundred = Bits(100, 8). Therefore, the number represented would be negative and could not be 200, becasue when added, there is more than 8 integers being called for.
12. What is the bit representation of negative zero? Explain your answer.
00000000
This would be the bit represetation of -0 becuase the first 0 bit in the byte would signify that it is a negative number and the remainder of the 0's would indicate the 0 integer.
13. What's the largest integer that can be represented in a single byte?
Explain your reasoning.
127 is the largest that can be represented by this format because you would need to use the first bit space to differentiate between positive and negative then the reamining combinations would leave possibility for 127.
14. What's the smallest integer that can be represented in a single byte?
Explain your reasoning.
-127 for the same reasoning. The numbers can be positive or negative then the reamining bits would make the byte.
15. What's the largest integer that can be represented in `n` bits?
Explain your reasoning.
## Text questions
@ -102,4 +131,15 @@ talk with others.
Make a hypothesis about how this could work.
Initially I thought it would be something signifyed in the last two bits of the
byte. However, I don't think it is the order of the two because there is not
consistency that I can see in the examples above.
Maybe it has to do with the number of bits total. Would it be possible for the
initial characters of the alphabet to be signifyed by 8 bits and everything beyond that
is assigned more than that. Or possibly there could be a built in loop of some kind at the 8th bit.
It could run some sort of if, then sequence. If the first 8 are a byte that creates a letter,
then the computer generates that character. If the first 8 is not a byte that correlates with
a character, then it continues to read the bites until it does.