How signed integers are represented using 16 bits

xkcdcant_sleep

Source: http://www.xkcd.com/571/

This probably requires a little explanation with the nuances of how integers are stored in computers. A 16-bit signed integer simulates binary digits with 16 digits, where the first digit represents either positive (0) or negative (1). Because this first digit represents positive or negative, the counting system is a little different than regular counting in binary.

For starters,

0000000000000000 represents 0

0000000000000001 represents 1

0000000000000010 represents 2

\vdots

0111111111111111111 represents 2^{16}-1 = 32767

For the next number, 1000000000000000, there’s a catch. The first 1 means that this should represent a negative number. However, there’s no need for this to stand for -0, since we already have a representation for 0. So, to prevent representing the same number twice, we’ll say that this number represents 0 - 32768 = -32768, and we’ll follow this rule for all representations starting with 1. So

0000000000000000 represents 0-32768 = -32768

0000000000000001 represents 1 - 32768 = -32767

0000000000000010 represents 2 - 32768 = -32766

\vdots

0111111111111111111 represents 32767-32768 = -1

Because of this nuance, the following C computer program will result in the unexpected answer of -37268 (symbolized by the sheep going backwards in the comic strip).

main()

{

      short x = 32767;

      printf(“%d \n”, x + 1);

}

For more details, see http://en.wikipedia.org/wiki/Integer_%28computer_science%29

Getting the right answer the wrong way

I just read “But My Physics Teacher Said… A Mathematical Approach to a Physical Problem,” which was a very interesting pedagogical article concerning the teaching of calculus. Here’s the central problem:

I included on their exam a question involving average velocity. I gave the students a quadratic function and asked them to calculate the average velocity over a given interval… One of my students… got the final numerical answer correct, but he hadn’t used the average velocity formula he had learned in our course. Instead… he had calculated the average of the velocities at the end points of the given interval. When I explained this to him, he stated that he didn’t understand the difference because he had learned the latter formula to calculate average velocity in his physics class.

It turns out that this alternative approach always work under the condition of constant acceleration (i.e., a quadratic function), and since constant acceleration is such an important special case in freshman physics, the formula was presented and the student remembered the formula. Of course, the student probably was not aware of the formula was only generally true under this specific circumstance.

After some pedagogical reflection, the author concluded

My student and I both learned from this experience. He gave me the opportunity to look at a familiar topic with the eye of a physicist, and I taught him the importance of context when using a formula. Specific adventures such as the one my student and I encountered will undoubtedly strengthen my approach to teaching this course and my students’ ability to think like mathematicians.

The full article can be found at http://digitaleditions.walsworthprintgroup.com/publication/?i=187509&p=19.

Gravity wells

xkcdgravity_wells

This is one of most creative diagrams that I’ve ever seen: the depth of various solar system gravity wells. A large version of this image can be accessed at http://xkcd.com/681_large/.

From the fine print:

Each well is scaled so that rising out of a physical well of that depth — in constant Earth surface gravity — would take the same energy as escaping from that planet’s gravity in reality.

Depth = \displaystyle \frac{G M}{g r}

It takes the same amount of energy to launch something on an escape trajectory away from Earth as it would to launch is 6,000 km upward under a constant 9.81 \hbox{m}/\hbox{s}^2 Earth gravity. Hence, Earth’s well is 6,000 km deep.

Here’s some more details about the above formula.

Step 1. The escape velocity from the surface of a spherical planet is

v = \displaystyle \sqrt{ \frac{2GM}{r} },

where G is the universal gravitational constant, M is the mass of the planet, and r is the radius of the planet. Therefore, the kinetic energy needed for a rocket with mass m to achieve this velocity is

E = \displaystyle \frac{1}{2} m v^2 = \frac{GMm}{r}

Step 2. Suppose that a rocket moves at constant velocity upward near the surface of the earth. Then the force exerted by the rocket exactly cancel the force of gravity, so that

F = mg,

where g is the acceleration due to gravity near Earth’s surface. Also, work equals force times distance. Therefore, if the rocket travels a distance d against this (hypothetically) constant gravity, then

E = mgd

The depth formula used in the comic is then found by equating these two expressions and solving for d.

Poorly worded homework problems

A personal pet peeve of mine are grade-school homework problems that are extremely poorly worded, thus leading to unnecessary confusion and bewilderment in students who (sadly) are already confused and bewildered more often than they (or we) would like. Here are two examples that I’ve seen recently.

(1) A worksheet gives the numbers 144 and 300 with the instructions “Find all of the ways to multiply to make each product. First, find the ways with two factors, and then find ways to multiply with more than two factors.”

The second half of the instructions can easily be interpreted by a child to mean “Find all of the ways to write 144 and 300 as a product with more than two factors.” This reading of the question (probably not intended by the author) will take even a gifted child a really, really long time to complete. Furthermore, I’m a professional mathematician, and even I have no idea off the top of my head if there’s an easy formula for the number of ways that a number can be expressed with an arbitrary number of factors greater than 1.

(2) A rocket blasts off. At 10.0 seconds after blast off, it is at 10,000 feet, traveling at 3600 mph. Assuming the direction is up, calculate the acceleration.

I assume that the author was trying to be cute by adding the “it is at 10,000 feet” part of the problem. Or the author wants the student to develop skill at weeding out unnecessary information (like the height) and identifying just the important information (the final velocity and the time) to calculate the quantity of interest.

But it’s aggravating that the information in the problem is not consistent, so there is no solution. In other words, it’s impossible for a rocket to travel with constant acceleration at travel 10000 feet at 3600 mph 10 seconds later.

To begin,

3600 \displaystyle \frac{\hbox{mile}}{\hbox{hour}} = 3600 \displaystyle \frac{\hbox{mile}}{\hbox{hour}} \times \displaystyle \frac{\hbox{5280 feet}}{\hbox{1 mile}} \times \displaystyle \frac{\hbox{1 hour}}{\hbox{3600 seconds}} = 5280\displaystyle \frac{\hbox{feet}}{\hbox{second}}.

Therefore, the (presumably constant) acceleration is

\displaystyle \frac{5280 \hbox{~feet/second}}{10 \hbox{~seconds}} = 528 \hbox{~feet/second}^2.

However, using calculus, we can compute the height of the rocket by integrating twice:

v(t) = \int 528 \, dt = 528t + v_0 = 528t

y(t) = \int 528t \, dt = 264t^2 + y_0 = 264t^2

Therefore, the height of the rocket after 10 seconds is y(10) = 26,400, not the 10,000 feet given in the problem.