Re: Weird results from Left Shift
| From: | Rasmus Lerdorf | Date: | Wed, 19 Sep 2001 21:38:16 +0000 |
| Subject: | Re: Weird results from Left Shift | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-67905@lists.php.net to get a copy of this message | ||
> <?php
> $num = 8;
> $num = decbin($num);
> echo "Number is $num<BR>";
> $num = $num << 1;
> echo "Shifted Number is $num";
> ?>
But you are using it wrong. decbin() returns a string with a binary
pattern in it. You can't shift a string. You shift numbers. If you
already know the decimal value of the number you want to shift you don't
have to do anything. I suggested bindec() because I thought you wanted to
provide a binary representation of the number for some reason.
-Rasmus