Commit 8376f49f authored by Alex Ne's avatar Alex Ne

Тулзы преобразования

parent fcbaf45a
<?php
namespace X\Tool\BC;
trait BcDecHex {
/**
* @param $dec
*/
protected function bcdechex($dec) {
$last = bcmod($dec, 16);
$remain = bcdiv(bcsub($dec, $last), 16);
if ($remain == 0) {
return dechex($last);
} else {
return bcdechex($remain) . dechex($last);
}
}
}
?>
\ No newline at end of file
<?php
namespace X\Tool\BC;
trait BcHexDec {
/**
* @param $hex
*/
protected function bchexdec($hex) {
if (strlen($hex) == 1) {
return hexdec($hex);
} else {
$remain = substr($hex, 0, -1);
$last = substr($hex, -1);
return bcadd(bcmul(16, bchexdec($remain)), hexdec($last));
}
}
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment