php-general | 2001092
Date: 09/19/01
- Next message: Jonathan Hilgeman: "[PHP] Sockets"
- Previous message: Rick Gardner: "Re: [PHP] preventing an include() from taking over?"
- Maybe in reply to: Sheridan Saint-Michel: "[PHP] Weird results from Left Shift"
- Next in thread: Rasmus Lerdorf: "Re: [PHP] Weird results from Left Shift"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> Okay, from the manual I have
> $a << $b - Shift the bits of $a $b steps to the left
>
> When I run the code
>
> <?php
> $num = "0001000";
> echo "Number is $num<BR>";
> $num = $num << 1;
> echo "Shifted Number is $num";
> ?>
>
> I get the output
>
> Number is 0001000
> Shifted Number is 2000
>
> What am I missing?!?
$num = "0001000"; sets $num to be 1000, not 0001000 binary.
As I'm not sure if PHP has a binary type, you can use hex:
<?php
$num = 0x8; // 0001000 binary
echo "Number is $num<BR>";
$num = $num << 1;
echo "Shifted Number is $num";
?>
Eric O'Connell
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Jonathan Hilgeman: "[PHP] Sockets"
- Previous message: Rick Gardner: "Re: [PHP] preventing an include() from taking over?"
- Maybe in reply to: Sheridan Saint-Michel: "[PHP] Weird results from Left Shift"
- Next in thread: Rasmus Lerdorf: "Re: [PHP] Weird results from Left Shift"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

