PHP implements decimal conversion to binary
function dec2bin ($dec) { $flag = array(); while ($dec != 0) {- array_push($flag,$dec%2);
- $dec = (int)$dec /2;
- }
- $binstr = '';
- while (!empty($flag)) {
- $binstr .= array_pop($flag);
- }
- return $binstr;
- }
-
-
- Copy code
|