TechniqueUse the decbin() and bindec() functions to convert back and forth: <?php $num = 23; $binary = decbin ($num); $decimal = bindec ($binary); print "The number $decimal is equivalent to the binary $binary"; ?> CommentsThe decbin() function converts a decimal number to its binary equivalent; in contrast, the bindec() function converts a binary number to its decimal equivalent. Another method is to use PHP's base_convert() function: <?php $num = 23; $binary = base_convert ($num, 10, 2); $decimal = base_convert ($binary, 2, 10); print "The number $decimal is equivalent to the binary $binary"; ?> |