29 $value = self::validateBinary($value);
31 return $e->getMessage();
34 if (strlen($value) == 10) {
36 $value = substr($value, -9);
38 return '-' . (512 - bindec($value));
41 return (
string) bindec($value);
65 public static function toHex($value, $places = null): string
69 $value = self::validateBinary($value);
72 return $e->getMessage();
75 if (strlen($value) == 10) {
76 $high2 = substr($value, 0, 2);
77 $low8 = substr($value, 2);
78 $xarr = [
'00' =>
'00000000',
'01' =>
'00000001',
'10' =>
'FFFFFFFE',
'11' =>
'FFFFFFFF'];
80 return $xarr[$high2] . strtoupper(substr(
'0' . dechex((
int) bindec($low8)), -2));
82 $hexVal = (string) strtoupper(dechex((
int) bindec($value)));
84 return self::nbrConversionFormat($hexVal, $places);
108 public static function toOctal($value, $places = null): string
112 $value = self::validateBinary($value);
115 return $e->getMessage();
118 if (strlen($value) == 10 && substr($value, 0, 1) ===
'1') {
119 return str_repeat(
'7', 6) . strtoupper(decoct((
int) bindec(
"11$value")));
121 $octVal = (string) decoct((
int) bindec($value));
123 return self::nbrConversionFormat($octVal, $places);
128 if ((strlen($value) > preg_match_all(
'/[01]/', $value)) || (strlen($value) > 10)) {
static toHex($value, $places=null)
toHex.
static toOctal($value, $places=null)
toOctal.
static validateBinary(string $value)
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
static toDecimal($value)
toDecimal.