Home > Backend Development > PHP Tutorial > Decimal to binary

Decimal to binary

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-25 08:48:17
Original
1145 people have browsed it
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
Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template