9/16/04
A student writes:
Dear Dr. Patt Question 1: I know we already did the binary and 2's complement, but I just wanted to make sure I get everything right. So, as I understand the only difference between binary and 2's complement is that we can have negative numbers in 2's complement, but binary is unsigned and as a result we can not have negative numbers.
You are picking at very fine points. Not clear I want to bog down everyone's brain with this. But as one of my TAs told me, as long as I warn you ahead of time, you can always delete, ...or save this for a rainy day.
So, then:
"Binary number system" simply means we are using a positional notation (i.e., the left one in 0101 is worth four times as much as the right one, due to its position), and there are two (binary) allowable digits, 0 and 1. Decimal, recall, there are ten allowable digits: 0, 1, 2, ... 9.
And there are several binary systems.
2's complement means we are using our n bits to represent integers between - 2^(n-1) to + [2^(n-1) -1]. Yes, positive and negatives, with the negative integers encoded in a very special way, as we discussed in class. There are ways to represent negative integers other than 2's complement. The table in chapter 2 contains two such ways.
Does that help, or just make it worse?
Question 2: In ch. 2 page 37 you mentioned that LC-3 has 15 bits of precision, but as I understand it can only represent integers between -2^15 and +(2^15)-1 so how can it have 15 bits of precision. Question 3: In the same section, it says that the range is 2^15. Range means from smallest number to the largest number so that is from -32768 to +32767 which is 65535, which is equal to 2^16.
Let me take these two together. I think I could have worded page 37 better. Guess there will have to be a 3rd edition! I wanted to introduce floating point by building on what you knew about integers. So, given the notion of sign and magnitude, I said: Hey! I need a bit for sign, leaving 15 bits for precision. Nothing wrong with that. In fact the motivation is probably good, since floats have a sign bit, range bits (exp) and precision bits. But then, I think I got carried away. I like the point you make about range better than the point I made in the book. The range is the distance from smallest to largest, which I have to agree is 2^16. With hindsight, I think I would have been better off not mentioning range with integers, since we usually use the term in discussions of floating point numbers.
Question 4: Using the float datatype, can we represent rational numbers where the denominator is not a multiple of 2.
Sure, although not "exactly," since every "1" corresponds to a power of 2.
Kind of like: can you represent 1/3 in decimal. Sure, although not "exactly." 0.33333333333333333333333333333333333333333333333333333... until you get tired.
For example how would we represent 2 and 3/7 in binary?
I will leave that for you, as an exercise. ...after getting you started, of course. Hint: Think of the algorithm for going from decimal to binary.
I assume the 2 is no problem. 10. ...
What about the 3/7? First multiply by 2 and see if you go over 1. Since no, we insert a 0 in the representation. That is: 10.0... and 6/7.
Multiply by 2 yields 12/7 which is greater than 1. Since yes, we insert a 1, and look at what is left. That is: 10.01... and 5/7.
And, so forth, until you get tired, or reach the end of the paper.
Thank you very much Dr. Patt
My pleasure.
Yale Patt
306 student: << name withheld to protect the one with good insights >>