Decimal to binary

WBOY
WBOYOriginal
2016-07-25 08:48:171114browse
PHP implements decimal conversion to binary
                 
                                                                                                                                                                                                                                                                                                                     


function dec2bin ($dec) {
$flag = array();
    while ($dec != 0) {
  1. array_push($flag,$dec%2);
  2. $dec = (int)$dec /2;
  3. }
  4. $binstr = '';
  5. while (!empty($flag)) {
  6.   $binstr .= array_pop($flag);
  7. }
  8. return $binstr;
  9. }
  10. Copy code
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn