[PHP] Weird results from Left Shift
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 $numBR; $num = $num 1; echo Shifted Number is $num; ? I get the output Number is 0001000 Shifted Number is 2000 What am I missing?!? Sheridan Saint-Michel Website Administrator FoxJet, an ITW Company www.foxjet.com
RE: [PHP] Weird results from Left Shift
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 $numBR; $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 $numBR; $num = $num 1; echo Shifted Number is $num; ? Eric O'Connell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Weird results from Left Shift
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 $numBR; $num = $num 1; echo Shifted Number is $num; ? I get the output Number is 0001000 Shifted Number is 2000 What am I missing?!? Use: $num = bindec(0001000); -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Weird results from Left Shift
I already tried that before posting the question. ?php $num = 8; $num = decbin($num); echo Number is $numBR; $num = $num 1; echo Shifted Number is $num; ? Gives me the output: Number is 1000 Shifted Number is 2000 Sheridan Saint-Michel Website Administrator FoxJet, an ITW Company www.foxjet.com - Original Message - From: Rasmus Lerdorf [EMAIL PROTECTED] To: Sheridan Saint-Michel [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, September 19, 2001 3:51 PM Subject: Re: [PHP] Weird results from Left Shift 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 $numBR; $num = $num 1; echo Shifted Number is $num; ? I get the output Number is 0001000 Shifted Number is 2000 What am I missing?!? Use: $num = bindec(0001000); -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Weird results from Left Shift
?php $num = 8; $num = decbin($num); echo Number is $numBR; $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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]