Jump to content

Recommended Posts

<< and >> are bitwise operators.  They perform binary operations on integers.  In particular, this line takes $c, multiplies it by $j, and then multiplies that result by 8.  It's slightly faster to say $something << 3; than $something * 8;  It's leftover from C programmers who used it a lot.

 

-Dan

Link to comment
https://forums.phpfreaks.com/topic/247297-double-left-arrow/#findComment-1270029
Share on other sites

how are 3 and 8 the same thing?

 

$something << 3;

$something * 8;

 

It's a bitwise operator for shifting bits to the left

 

http://php.net/manual/en/language.operators.bitwise.php

 

Read the article he linked. It was linked for a purpose. 3 and 8 are not the same. $x << 3 and $x * 8 are the same (essentially).

Link to comment
https://forums.phpfreaks.com/topic/247297-double-left-arrow/#findComment-1270045
Share on other sites

Here's what happens, step by step, if you're still confused

 

<?php 

// OUtput in plain text
header("Content-type: text/plain");

// Format is using 0 to pad the left side, 16 length, and binary
$format = '%016b';

$c = 5;
$j = 7;
echo '$c*$j:      '.sprintf($format,($c*$j))."\n";

echo '($c*$j)<<2: '.sprintf($format,(($c*$j)<<2))."\n";

echo 'Same as $c*$j with bits moved 2 to the left';

?>

 

$c*$j:      0000000000100011
($c*$j)<<2: 0000000010001100
Same as $c*$j with bits moved 2 to the left

Link to comment
https://forums.phpfreaks.com/topic/247297-double-left-arrow/#findComment-1270065
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.