Written by Vincent

Please ConvertToEnglish()

So, I thought it would be interesting to do something different. How about deciphering code? The challenge is to explain a piece of code by giving a minimalist description in English. We’ll practise understanding code with no comments and only the surrounding context as clues.

Here’s the code

int foo(int para)
{
	int temp = para << 3;
	return temp + temp + temp;
}

Explain what the function is doing in the simplest possible way. Don't just tell me what it's doing line by line. Tell me what it finally does.

Post your answer in a comment. Bonus points if you can give a reason why it was coded that way (yes, it has a rational explanation). I'll post my answer in a few days time.

Enjoyed reading this? Share it!
  • HackerNews
  • Reddit
  • Slashdot
  • FriendFeed
  • StumbleUpon
  • Facebook
  • del.icio.us
  • Posterous

Tags: ,

Published on 16 July 2008

Comments

3 Responses to “Please ConvertToEnglish()”

  1. Mark Ingram on 16 July 2008 9:16 pm

    It multiplies the input by 24.

    e.g.

    foo(1) = 24
    foo(2) = 48
    foo(3) = 72

    No idea why it’s written that way?

  2. Vincent Tan on 16 July 2008 10:28 pm

    Mark, that’s correct. As for the bonus answer, it’s not so much the multiplying by 24 part, but the way the calculation was performed.

    I’ll post the answer on Friday (got a post lined up for tomorrow already). Hint: it’s something in the area of game programming and a bit of its history.

  3. Multiplications, additions and bit shifts | Polymath Programmer on 21 July 2008 5:01 pm

    [...] a previous article, I asked what this [...]

Leave a Reply

I reserve the right to delete offensive, spammy and/or unintelligible (based on context) comments. I do read all comments, even if it takes a while for me to respond. Polite criticism is fine. Rude ones will be deleted (right after I correct the error of course).