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
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)));
108 public static function toOctal($value, $places =
null): string
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));
128 if ((strlen($value) > preg_match_all(
'/[01]/', $value)) || (strlen($value) > 10)) {
An exception for terminatinating execution or to throw for unit testing.
static nbrConversionFormat(string $value, ?int $places)
Formats a number base string value with leading zeroes.
static validatePlaces($places=null)
static validateValue($value)
static toDecimal($value)
toDecimal.
static validateBinary(string $value)
static toHex($value, $places=null)
toHex.
static toOctal($value, $places=null)
toOctal.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.