nave-wata / base-conversion
This is a simple PHP class to convert numbers from one base to another.
v1.0.0
2024-03-03 13:04 UTC
Requires
- php: 8.*
- ext-bcmath: *
Requires (Dev)
- phpunit/phpunit: ^9.6
README
This is a simple PHP class to convert numbers from one base to another.
It provides methods to perform conversions between binary, decimal, and hexadecimal numbers. It can also perform conversions between arbitrary radix numbers.
Installation
composer require nave-wata/base-conversion
Usage
use NaveWata\BaseConversion\BaseConversion; // Convert from binary BaseConversion::binaryToDecimal('1111'); // 15 BaseConversion::binaryToHexadecimal('1111'); // F // Convert from decimal BaseConversion::decimalToBinary('2'); // 10 BaseConversion::decimalToHexadecimal('15'); // F // Convert from hexadecimal BaseConversion::hexadecimalToBinary('F'); // 1111 BaseConversion::hexadecimalToDecimal('F'); // 15 // Custom conversion $custom = new BaseConversion('abcdefghijklmnopqrstuvwxyz'); $custom->decimalToCustom('25'); // z $custom->customToDecimal('z'); // 25