PHP code example of rafalswierczek / numeral-system
1. Go to this page and download the library: Download rafalswierczek/numeral-system library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rafalswierczek / numeral-system example snippets
// 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');