note 94552 modified in language.operators.bitwise by danbrown

From: Date: Wed, 11 Nov 2009 18:12:18 +0000
Subject: note 94552 modified in language.operators.bitwise by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162773@lists.php.net to get a copy of this message
Okay, I'm twelve, and I am new to PHP, but I created the following -simple- functions: <?php function Isdec($num) { if(round($num)==$num) { return false; } else { return true; } } function decshiftl($number, $amount){ if(Isdec($number)) { $decimal = substr($number, (strlen($number) - round($number) + 1)); $decimal*=pow(10,strlen($decimal) - 1); $Shiftl = ($number << $amount) + (($decimal << $amount) / pow(10,strlen($decimal))); } else { $Shiftl = $number << $amount; } return $Shiftl; } function decshiftr($number, $amount){ if(Isdec($number)) { $decimal = substr($number, (strlen($number) - round($number) + 1)); $decimal*=pow(10,strlen($decimal) - 1); $Shiftr = ($number >> $amount) + (($decimal >> $amount) / pow(10,strlen($decimal))); } else { $Shiftr = $number >> $amount; } return $Shiftr; } ?> Anyway, it's just shoving parameters in to an equation, but sometimes reinventing the wheel and putting rockets on it is a good thing. --was-- Okay, I'm twelve, and I am new to PHP, but I created the following -simple- functions: <?php function Isdec($num) { if(round($num)==$num) { return false; } else { return true; } } function decshiftl($number, $amount){ if(Isdec($number)) { $decimal = substr($number, (strlen($number) - round($number) + 1)); $decimal*=pow(10,strlen($decimal) - 1); $Shiftl = ($number << $amount) + (($decimal << $amount) / pow(10,strlen($decimal))); } else { $Shiftl = $number << $amount; } return $Shiftl; } function decshiftr($number, $amount){ if(Isdec($number)) { $decimal = substr($number, (strlen($number) - round($number) + 1)); $decimal*=pow(10,strlen($decimal) - 1); $Shiftr = ($number >> $amount) + (($decimal >> $amount) / pow(10,strlen($decimal))); } else { $Shiftr = $number >> $amount; } return $Shiftr; } ?> Anyway, it's just shoving parameters in to an equation, but sometimes reinventing the wheel and putting rockets on it is a good thing. If you have any advice on how to optimize it, it would be apppreciated. http://php.net/manual/en/language.operators.bitwise.php

« previous php.notes (#162773) next »