Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Meaning of <<

Posted on 2005-05-16
10
Medium Priority
?
233 Views
Last Modified: 2006-11-18
Hi

What's the meaning of "<<" at "$i = $h << $c;" ?

Thanks
0
Comment
Question by:hasozduru
  • 7
  • 3
10 Comments
 
LVL 9

Expert Comment

by:keteracel
ID: 14012382
it means bitwise shift left.

if $h = 1 and $c = 1 then $i = 2
if $h = 1 and $c = 2 then $i = 4
if $h = 3 and $c = 1 then $i = 6
if $h = 3 and $c = 2 then $i = 12
etc...
0
 
LVL 9

Expert Comment

by:keteracel
ID: 14012394
it's all to do with binary data, i.e. the first example I gave above lloks like this:

00000001 << 00000001 = 00000010
0
 
LVL 9

Expert Comment

by:keteracel
ID: 14012403
you see the bit moves up by the relevant amount of bits
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:hasozduru
ID: 14012423
Ok what does $a <<= 2; mean?
0
 
LVL 9

Expert Comment

by:keteracel
ID: 14012433
that means shift $a to the left by two bits and assign the result to $a
0
 

Author Comment

by:hasozduru
ID: 14012487
Let say $a = 2 and we write $a <<= 2; and then we type echo $a. What will be the output?
0
 
LVL 9

Expert Comment

by:keteracel
ID: 14012495
8
0
 
LVL 9

Accepted Solution

by:
keteracel earned 2000 total points
ID: 14012514
00000010 << 2 = 00001000

and binary reads 128, 64, 32, 16, 8, 4, 2, 1
0
 

Author Comment

by:hasozduru
ID: 14012695
How does the following works? (if it's a odd value)

$a = 3;
$a <<= 2;
0
 
LVL 9

Expert Comment

by:keteracel
ID: 14012755
if $a is odd, then it seems that php does something different to other languages in that -1 shifted up by one is -2
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question