CompOrg Spring 2005 - HW1 FAQ

Click on a question to expand it (for the details).
Click on the question title again to hide the details.

+ Using the pow function (math library)

Question:

I was wondering if it was legal to use math.h's "pow(double, double)" function for the binary_to_int function. (I use it to calculate powers of two.) The reason for my concern is that the sample main.c code had several #includes, but math.h was not one of them.


Answer:

You can use math functions, we will make sure it is linked with -lm. You need to make sure <math.h> is included in your code.

Note that there are much easier ways (logic operations instead of using the pow function...).

+ Powers of 2 using logic operations?

Question:

How can I compute powers of 2 using logic operations?


Answer:

Recall that a left shift (of an integer) corresponds to doubling the value, so the expression x<<1 is just like x*2. Shifting to the left twice (x<<2) is like multiplying by 4 (22). The expression 0x01 << n is computing 2n.

+ Re-submitting

Question:

I don't seem to be able to re-submit!


Answer:

It's fixed now.