Home  >  Article  >  Backend Development  >  What are the functions for converting php to binary?

What are the functions for converting php to binary?

青灯夜游
青灯夜游Original
2022-04-26 20:39:232567browse

php functions to convert to binary: 1. The decbin() function can convert decimal numbers to binary, the syntax is "decbin (decimal value)"; 2. The base_convert() function can convert any decimal value Convert to binary, the syntax is "bindec(arbitrary base value, original base number, 2)".

What are the functions for converting php to binary?

The operating environment of this tutorial: Windows7 system, PHP7. Version 1, DELL G3 computer

There are two functions for converting php to binary:

  • decbin() function

  • base_convert() function

#1. Use the decbin() function

The decbin() function can convert decimal numbers into Binary numbers.

<?php
echo decbin(3) . "<br>";
echo decbin(1) . "<br>";
echo decbin(1587) . "<br>";
echo decbin(7);
?>

What are the functions for converting php to binary?

#2. Use the base_convert() function

The base_convert() function can be used between any bases Conversion, convert the specified original base system into the target base system, just set the original base system and the base system to be converted.

<?php
echo base_convert(2,10,2) . "<br>";
echo base_convert("cceeff",16,2) . "<br>";
echo base_convert("JZG8X",36,2) . "<br>";
echo base_convert("2003001",17,2);
?>

What are the functions for converting php to binary?

Recommended learning: "PHP video tutorial

The above is the detailed content of What are the functions for converting php to binary?. For more information, please follow other related articles on the PHP Chinese website!

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