# What is << ?

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
I was taking an online PHP test and got the question

What will the output of the following statement be

echo 4<<5;

After the test, I searched google but couldn't find any such
operator/construct.
Can any one explain what '<<' does?

Thanks

## Re: What is << ?

Hello,

mab464 wrote:

That's a bitwise operation.

http://be.php.net/language.operators.bitwise .

- Jensen

## Re: What is << ?

search for "computer number system" in google, then search for base 2
numbers.Then come to bit operators.

## Re: What is << ?

I find that to be odd advice.  I'm very much in favor of "Google it" as a
first-stage answer, but your search terms would imply that the << operator
is a generic part of binary arithmetic.  That's not true.  The << operator
was a C language invention, and in order to learn that "<<" is the "left
shift operator", you have to stumble upon a reference for a programming
language that implements it.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

## Re: What is << ?

opps.. got it.. you are correct.. Boolean logic never talks about shifts.
Shifts are Register specific..
Correct me if i am wrong..

## Re: What is << ?

sathyashrayan wrote:

A left shift is multiply by two, in binary arithmetic, assuming the MSB
is << that way..

IN the days before optimising compilers on small micros, the sort of :-

aa<<1;
a++;

was a LOT faster than:-

a=a*3;

For example..

## Re: What is << ?

The Natural Philosopher wrote:

Except they give two entirely different answers...

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

## Re: What is << ?

Jerry Stuckle wrote:

Not for a=1 :=)

it shold have course been

b=a<<1;
a=b+a;

## Re: What is << ?

According to PHP for Beginners:

<<    >>  Shift left,    shift right (bitwise)

128.

D. Stussy wrote:

42

## Re: What is << ?

Wrong.  Not possible.  To get 42, one would have to use "base 31.5," but
half a digit isn't possible, nor does it make sense.

## Re: What is << ?

D. Stussy wrote:

Whoosh!

(That's the sound of a joke going right over your head) :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

## Re: What is << ?

Not impossible, just improbable.  If one wants the answer to the meaning
of life, that's the sort of work one must go thru.  <g>

## Re: What is << ?

D. Stussy wrote:

I am impressed that you even tried to make sense of it.