42 public static function toBinary($value, $places =
null): string
49 return $e->getMessage();
52 $value = (int) floor((
float) $value);
53 if ($value > self::LARGEST_BINARY_IN_DECIMAL || $value < self::SMALLEST_BINARY_IN_DECIMAL) {
89 public static function toHex($value, $places =
null): string
96 return $e->getMessage();
99 $value = floor((
float) $value);
100 if ($value > self::LARGEST_HEX_IN_DECIMAL || $value < self::SMALLEST_HEX_IN_DECIMAL) {
103 $r = strtoupper(dechex((
int) $value));
109 public static function hex32bit(
float $value,
string $hexstr,
bool $force =
false): string
111 if (PHP_INT_SIZE === 4 || $force) {
112 if ($value >= 2 ** 32) {
113 $quotient = (int) ($value / (2 ** 32));
115 return strtoupper(substr(
'0' . dechex($quotient), -2) . $hexstr);
117 if ($value < -(2 ** 32)) {
118 $quotient = 256 - (int) ceil((-$value) / (2 ** 32));
120 return strtoupper(substr(
'0' . dechex($quotient), -2) . substr(
"00000000$hexstr", -8));
155 public static function toOctal($value, $places =
null): string
162 return $e->getMessage();
165 $value = (int) floor((
float) $value);
166 if ($value > self::LARGEST_OCTAL_IN_DECIMAL || $value < self::SMALLEST_OCTAL_IN_DECIMAL) {
170 $r = substr(
$r, -10);
177 if (strlen($value) > preg_match_all(
'/[-0123456789.]/', $value)) {
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 hex32bit(float $value, string $hexstr, bool $force=false)
const SMALLEST_BINARY_IN_DECIMAL
const SMALLEST_HEX_IN_DECIMAL
static toOctal($value, $places=null)
toOctal.
const LARGEST_OCTAL_IN_DECIMAL
static toBinary($value, $places=null)
toBinary.
static validateDecimal(string $value)
const LARGEST_HEX_IN_DECIMAL
const LARGEST_BINARY_IN_DECIMAL
const SMALLEST_OCTAL_IN_DECIMAL
static toHex($value, $places=null)
toHex.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.