delhombre / binary-converter
A simple and efficient package to convert numbers to their binary equivalent using PHP
v1.0.2
2024-01-07 15:41 UTC
Requires
- php: >=8.1.0
Requires (Dev)
- laravel/pint: ^1.13
- pestphp/pest: ^2.28
- phpstan/phpstan: ^1.10
- rector/rector: ^0.18.13
- symfony/var-dumper: ^7.0
README
BinaryConverter is a PHP library that converts binary numbers to decimal numbers and vice versa. It also supports hexadecimal conversion.
Get Started
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.