BinaryConverter is a PHP library that converts binary numbers to decimal numbers and vice versa. It also supports hexadecimal conversion.
Requires PHP 8.1+
First, install BinaryConverter via the Composer package manager:
composer require delhombre/binary-converter
Then, interact with the package:
$converter = BinaryConverter::from(2024);
$bin = $converter->toBinary();
dd($bin); // "11111101000"
You can pass the input as a string or as an integer.
dd(BinaryConverter::from('2024')->toBinary()); // "11111101000"
But sometimes you may want to convert a binary number to a decimal number. You can do it by passing the inputType parameter like this:
dd(BinaryConverter::from('11111101000', 'binary')->toDecimal()); // 2024
BinaryConverter PHP is an open-sourced software licensed under the MIT license.