35 public static function toBinary($value, $places = null): string
39 $value = self::validateHex($value);
42 return $e->getMessage();
45 $dec = self::toDecimal($value);
70 $value = self::validateHex($value);
72 return $e->getMessage();
75 if (strlen($value) > 10) {
80 foreach (str_split($value) as $char) {
81 $binX .= str_pad(base_convert($char, 16, 2), 4,
'0', STR_PAD_LEFT);
83 if (strlen($binX) == 40 && $binX[0] ==
'1') {
84 for (
$i = 0;
$i < 40; ++
$i) {
85 $binX[
$i] = ($binX[
$i] ==
'1' ?
'0' :
'1');
88 return (
string) ((bindec($binX) + 1) * -1);
91 return (
string) bindec($binX);
123 public static function toOctal($value, $places = null): string
127 $value = self::validateHex($value);
130 return $e->getMessage();
133 $decimal = self::toDecimal($value);
140 if (strlen($value) > preg_match_all(
'/[0123456789ABCDEF]/', $value)) {
static toDecimal($value)
toDecimal.
static toOctal($value, $places=null)
toOctal.
static toBinary($value, $places=null)
toBinary.
static toBinary($value, $places=null)
toBinary.
static toOctal($value, $places=null)
toOctal.
static validateHex(string $value)
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.