The decbin
method in PHP can be used to convert a decimal number to a binary string.
decbin(int $num): string
The argument is the decimal number that will be converted to binary.
decbin
returns the binary value of the argument as a string.
<?php$num = 1;echo "binary value of ". $num. " is: ". decbin($num)."\n";$num = 2;echo "binary value of ". $num. " is: ". decbin($num)."\n";$num = 3;echo "binary value of ". $num. " is: ". decbin($num)."\n";$num = 4;echo "binary value of ". $num. " is: ". decbin($num)."\n";$num = 5;echo "binary value of ". $num. " is: ". decbin($num)."\n";$num = 6;echo "binary value of ". $num. " is: ". decbin($num)."\n";$num = 7;echo "binary value of ". $num. " is: ". decbin($num)."\n";$num = 8;echo "binary value of ". $num. " is: ". decbin($num)."\n";?>
In the code above, we use the decbin
method to convert the decimal numbers from 1
to 8
into binary representation.