Type conversion#
To working string#
- from_int(int $value, int $sizeof) string#
Imports a regular PHP int.
- Parameters:
$value (
int) – The value. Negative values are accepted but they will be cast to unsigned$sizeof (
int) – Length of the unsigned number in bytes.
- Returns:
Binary string in the form this library accepts
If
$sizeof <= PHP_INT_SIZE, value may be truncated. (but do you really need this lib then?)
- from_hex(string $value, int $sizeof) string#
Imports a number written as a hexadecimal string.
- Parameters:
$value (
string) – String of hex digits$sizeof (
int) – Length of the unsigned number in bytes
- Returns:
Binary string in the form this library accepts
If
strlen($value) >= $sizeof * 2, value may be truncated.
- from_dec(string $value, int $sizeof) string#
Imports a number written as a decimal string.
- Parameters:
$value (
string) – String of digits$sizeof (
int) – Length of the unsigned number in bytes
- Returns:
Binary string in the form this library accepts
If
intval($value) >= 2 ** $sizeof, value will be truncated.
- from_base(string $value, int $base, int $sizeof) string#
Imports a number written in base specified in $base.
- Parameters:
$value (
string) – String of digits$base (
int) – Number base between 2 and 36$sizeof (
int) – Length of the unsigned number in bytes
- Returns:
Binary string in the form this library accepts
If
intval($value) >= 2 ** $sizeof, value will be truncated.
From working string#
- fits_into_int(string $value) bool#
- Parameters:
$value (
string) – Binary string in the form this library accepts
- Returns:
If value can be represented as a native PHP integer value, i.e. less than
PHP_INT_MAX.
- to_int(string $value) int#
- Parameters:
$value (
string) – Binary string in the form this library accepts
- Returns:
The int representation
- to_signed_int(string $value) int#
If the most significant bit is set, return value as a negative int.
- Parameters:
$value (
string) – Binary string in the form this library accepts
- Returns:
The int representation
- to_hex(string $value) bool#
Exports a number to a hexadecimal string.
- Parameters:
$value (
string) – Binary string in the form this library accepts
- Returns:
String of hex digits
- to_dec(string $value) bool#
Exports a number to a decimal string.
- Parameters:
$value (
string) – Binary string in the form this library accepts
- Returns:
String of digits
- to_base(string $value, int $base) bool#
Exports a number to a string in a specified base.
- Parameters:
$value (
string) – Binary string in the form this library accepts$base (
int) – Number base between 2 and 36
- Returns:
String of digits