Home  >  Article  >  Backend Development  >  How to convert decimal to binary in php

How to convert decimal to binary in php

WBOY
WBOYOriginal
2022-02-22 15:14:062768browse

In PHP, you can use the decbin() function to convert a decimal number into a binary number. The return result of this function is a binary number containing a decimal value. The syntax is "decbin(number);".

How to convert decimal to binary in php

The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.

How to convert decimal to binary in php

The decbin() function converts decimal numbers into binary numbers.

To convert binary to decimal, please see bindec() function

Syntax

decbin(number);

Parameter Description

number Required. Specifies the decimal value to be converted.

Return value: A string containing a binary number with a decimal value.

Examples are as follows:

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

Output results:

How to convert decimal to binary in php

## Recommended learning: "

PHP Video Tutorial

The above is the detailed content of How to convert decimal to binary in php. 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