note 32521 modified in function.bindec by irchtml

From: Date: Sat, 16 Oct 2004 09:17:03 +0000
Subject: note 32521 modified in function.bindec by irchtml
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-78653@lists.php.net to get a copy of this message
## calculate binary with "shift-method" ## <?php function dec2bin($decimal_code){ for($half=($decimal_code);$half>=1;$half=(floor($half))/2){ if(($half%2)!=0){ $y.=1; } else{ $y.=0; } } $calculated_bin=strrev($y); return $calculated_bin; } ?> ## example ## [bin] 123 = [dec] 1111011 e.g. 123/2 = 61,5 => 1 61/2 = 30,5 => 1 30/2 = 15 => 0 15/2 = 7,5 => 1 7/2 = 3,5 => 1 3/2 = 1,5 => 1 1/2 = 0,5 => 1 (0/2 = 0 finish) --was-- ## calculate binary with "shift-method" ## <?php function dec2bin($decimal_code){ for($half=($decimal_code);$half>=1;$half=(floor($half))/2){ if(($half%2)!=0){ $y.=1; } else{ $y.=0; } } $calculated_bin=strrev($y); return $calculated_bin; } ?> ## example ## [bin] 123 = [dec] 1111011 e.g. 123/2 = 61,5 => 1 61/2 = 30,5 => 1 30/2 = 15 => 0 15/2 = 7,5 => 1 7/2 = 3,5 => 1 3/2 = 1,5 => 1 1/2 = 0,5 => 1 (0/2 = 0 finish) http://php.net/manual/en/function.bindec.php

« previous php.notes (#78653) next »