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

This package is auto-updated.

Last update: 2024-06-07 16:48:32 UTC


README

BinaryConverter PHP

GitHub Workflow Status (main) Total Downloads Latest Version License

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.