composer require rafalswierczek/numeral-system
toBin
- converts data to binary:
��
toBinString
- converts data to binary string:
1010000011001111
toHexString
- converts data to hexagonal string:
A0CF
toInt
- converts data to positive integer:
41167
// 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');