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 (int) – 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 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