Skip to content

Latest commit

 

History

History
50 lines (38 loc) · 1.73 KB

README.md

File metadata and controls

50 lines (38 loc) · 1.73 KB

Simple numeral system conversion

Supported systems are binary, hexagonal and decimal.

Installation:

composer require rafalswierczek/numeral-system

Possible methods are:

  1. toBin - converts data to binary:

��

  1. toBinString - converts data to binary string:

1010000011001111

  1. toHexString - converts data to hexagonal string:

A0CF

  1. toInt - converts data to positive integer:

41167

Usage:

// in this example initial value is binary but it can be any of four above
$binary = random_bytes(4);

// all possible methods are used:
$hexStringBC = BinConverter::toHexString($binary);
$binaryStringHSC = HexStringConverter::toBinString($hexStringBC);
$hexStringBSC = BinStringConverter::toHexString($binaryStringHSC);
$intHSC = HexStringConverter::toInt($hexStringBSC);
$hexStringIC = IntConverter::toHexString($intHSC);
$binaryHSC = HexStringConverter::toBin($hexStringIC);
$binaryBSC = BinStringConverter::toBin($binaryStringHSC);
$binaryIC = IntConverter::toBin($intHSC);
$binaryStringIC = IntConverter::toBinString($intHSC);
$binaryStringBC = BinConverter::toBinString($binaryHSC);
$intBC = BinConverter::toInt($binaryIC);
$intBSC = BinStringConverter::toInt($binaryStringIC);

print_r(($binaryHSC === $binaryBSC && $binaryHSC === $binaryIC ? 'OK' : 'ERROR') . ' | binary: HSC === BSC === IC');
echo "\n";

print_r(($binaryStringBC === $binaryStringHSC && $binaryStringBC === $binaryStringIC ? 'OK' : 'ERROR') . ' | binary string: BC === HSC === IC');
echo "\n";

print_r(($hexStringBC === $hexStringBSC && $hexStringBC === $hexStringIC ? 'OK' : 'ERROR') . ' | hex string: BC === BSC === IC');
echo "\n";

print_r(($intBSC === $intHSC && $intBSC === $intBC ? 'OK' : 'ERROR') . ' | int: BSC === HSC === BC');