How to use decbin() Function In PHP
The decbin() function converts the given decimal number to the binary number. It returns a string containing a binary representation of the given decimal number argument. decbin stands for decimal to binary.
Syntax:
string decbin( $value )
Example:
PHP
<?php $decNum = 42; $binNum = decbin ( $decNum ); echo "Binary Number: " . $binNum ; ?> |
Binary Number: 101010
Decimal to Binary Conversion in PHP
Given a Decimal Number, and the task is to convert a given Decimal Number to a Binary Number using PHP.
Examples:
Input: 10
Output: 1010
Input: 25
Output: 11001
There are different methods to convert the Decimal to a Binary number, these are:
Table of Content
- Using decbin() Function
- Using Conversion Algorithm
- Using Recursion