A number of people have asked for more practice problems, to help with the kinds of questions that seem to recur on problem sets and exams. As I've said to several of you, it's so hard to invent good exam questions that I hate to give away professional secrets, but at the same time, the goal is for people to learn the material. So I will try to put things in this file that might be helpful. Most are sketchily explained, and just for drill.
And this list is for the whole year, so some of these won't make sense until later. Give them a shot anyway.
I'll try to add to this page as things occur to me, so check it out from time to time.
Powers of two and of ten recur, often in questions about how long it takes for something to become 1000 or 1000000 times bigger or smaller, or to figure out how big some binary number is. These are all easily done with almost no computation if you are completely familiar with the fact that
Count by 10 on the one side and by 3 on the other. The approximation gets worse as the exponents get bigger, but it's good enough for any question that will arise in this class. For practice, give approximate decimal answers for these:
Don't forget that you can factor; for example, 2^24 is 2^4 * 2^20, or close to 16 * 10^6.
For practice, how many bits for
The value you are computing here -- how many bits does it take -- is also the log (base 2, and rounded up) of the number of items. So what is the log base 2 of
If the question also asks for bytes, then round up the number of bits to the next multiple of 8 (e.g., 1-8 bits = 1 bytes, 9-16 bits = 2 bytes, and so on).
Sometimes the specific assignment of bits to values has numeric significance -- you really do want to do arithmetic or compare smaller and bigger. In that case, remember that n bits stores 2^n distinct values which will take on the numeric values 0 through 2^n - 1 inclusive.
The other way around is to compute how many and what values you can represent with something that uses bits. How many different values can you represent with
What can you say about the binary representation of a number divisible by 2? 4? 8?
Just as binary has a numeric value, so does hex, derived from the binary value, or treated as a number in base 16.
Hex is used as a shorthand for binary values in places like RGB colors, ASCII and Unicode tables, instruction encodings for computers, and so on.
Which color is the strongest in each of these? Which is least?
What value does this store in w?
if (x < y) w = x else w = y
What value does this store in w?
if (x < 0) w = -x else w = x
This is supposed to print 1, 2, 3, ..., 10. Fix it.
n = 0 while (n < 10) { print n }
This is supposed to print even numbers from 1 to 10 inclusive:
n = 1 while (n < 10) { print n n = n + 2 }
There are some physical properties that also depend on a linear dimension, notably area and volume. Don't forget that area grows in proportion to the square of the linear dimension, while volume grows in proportion to the cube.