Web Paint-by-Number Forum
Comments on Puzzle #15507: computer geek # 2
By Sarah Andrews (sarah)

peek at solution       solve puzzle
  quality:   difficulty:   solvability: line logic only  

Puzzle Description:

you think (x<<6)+(x<<4) is a perfectly natural way to multiply by 80.

#1: Lilly Johns (LJohns315) on Aug 11, 2011

Funny series, Sarah!
#2: karl (keicher) on Aug 11, 2011
yeah... hilarious.
#3: John Macdonald (perlwolf) on Aug 11, 2011 [SPOILER]
I thought picture meant "you are more interested in using the computer than personal hygiene" (I read it as BO.)
#4: Tom O'Connell (sensei69) on Aug 13, 2011
guess i'm not a geek, i have no idea of this
#5: Joe (infrapinklizzard) on Sep 30, 2016 [SPOILER]
As long as x is unsigned and an integer <820 or a byte <4.

"<<" means "shift left". Each time you shift the bits left you effectively multiply the number by 2.

So the notation above means multiply x by 64, and then multiply x by 16, and then add the two results together. Which is the same as multiplying x by 80.

Except that shifting the bits left is much much MUCH faster than using a multiplication instruction. This was very important when computers were less than a thousandth as fast as they are now. Even now stuff like this is used in cutting-edge graphics-intensive games.
#6: Greggo (Greggo) on Feb 18, 2018
Very interesting. What computer language is this?
#7: Joe (infrapinklizzard) on Feb 18, 2018 [SPOILER]
Most languages (at least in the past) have a shift left and shift right command. In some it's spelled out like shl and shr and others have an operand like << and >> for it.

It's such a useful thing for optimizing that only languages that try to keep you from doing stupid things don't have it. It is very easy to use this wrongly and mess things up severely.

(My programming knowledge is out of date, and it may be that all the modern OOP ones discourage this.)
#8: John Macdonald (perlwolf) on Feb 20, 2018
The canonical popular language that had the shift operators was C (and its predecessor B, and I think also their predecessor BCPL). It tends to be included in languages that are trying to be "high-level assembler" languages - powerful to program in yet still close enough to machine language that the programmer can usually have a good idea of the speed of various ways of writing code. Many languages since then have adopted shift operations, but many have not.

Goto next topic

You must register and log in to be able to participate in this discussion.