Class PelConvert

Description

Conversion functions to and from bytes and integers.

The functions found in this class are used to convert bytes into integers of several sizes (bytesToShort, bytesToLong, and bytesToRational) and convert integers of several sizes into bytes (shortToBytes and longToBytes).

All the methods are static and they all rely on an argument that specifies the byte order to be used, this must be one of the class constants LITTLE_ENDIAN or BIG_ENDIAN. These constants will be referred to as the pseudo type PelByteOrder throughout the documentation.

Located in /PelConvert.php (line 56)


	
			
Class Constant Summary
 BIG_ENDIAN = false
 LITTLE_ENDIAN = true
Method Summary
 int bytesToByte (string &$bytes, int $offset)
 void bytesToDump (string $bytes, int $max)
 int bytesToLong (string &$bytes, int $offset, PelByteOrder $endian)
 array bytesToRational (string &$bytes, int $offset, PelByteOrder $endian)
 int bytesToSByte (string &$bytes, int $offset)
 int bytesToShort (string &$bytes, int $offset, PelByteOrder $endian)
 int bytesToSLong (string &$bytes, int $offset, PelByteOrder $endian)
 array bytesToSRational (string &$bytes, int $offset, PelByteOrder $endian)
 int bytesToSShort (string &$bytes, int $offset, PelByteOrder $endian)
 string longToBytes (int $value, PelByteOrder $endian)
 string shortToBytes (int $value, PelByteOrder $endian)
Methods
bytesToByte (line 133)

Extract an unsigned byte from a string of bytes.

  • return: the unsigned byte found at offset, e.g., an integer in the range 0 to 255.
  • static:
int bytesToByte (string &$bytes, int $offset)
  • string &$bytes: the bytes.
  • int $offset: the offset. The byte found at the offset will be returned as an integer. The must be at least one byte available at offset.
bytesToDump (line 316)

Format bytes for dumping.

This method is for debug output, it will format a string as a hexadecimal dump suitable for display on a terminal. The output is printed directly to standard out.

  • static:
void bytesToDump (string $bytes, int $max)
  • string $bytes: the bytes that will be dumped.
  • int $max: the maximum number of bytes to dump. If this is left out (or left to the default of 0), then the entire string will be dumped.
bytesToLong (line 223)

Extract an unsigned long from bytes.

  • return: the unsigned long found at offset, e.g., an integer in the range 0 to 4294967295.
  • static:
int bytesToLong (string &$bytes, int $offset, PelByteOrder $endian)
  • string &$bytes: the bytes.
  • int $offset: the offset. The long found at offset will be returned as an integer. There must be at least four bytes available beginning at the offset given.
  • PelByteOrder $endian: one of LITTLE_ENDIAN and BIG_ENDIAN.
bytesToRational (line 276)

Extract an unsigned rational from bytes.

  • return: the unsigned rational found at offset, e.g., an array with two integers in the range 0 to 4294967295.
  • static:
array bytesToRational (string &$bytes, int $offset, PelByteOrder $endian)
  • string &$bytes: the bytes.
  • int $offset: the offset. The rational found at offset will be returned as an array. There must be at least eight bytes available beginning at the offset given.
  • PelByteOrder $endian: one of LITTLE_ENDIAN and BIG_ENDIAN.
bytesToSByte (line 150)

Extract a signed byte from bytes.

  • return: the signed byte found at offset, e.g., an integer in the range -128 to 127.
  • static:
int bytesToSByte (string &$bytes, int $offset)
  • string &$bytes: the bytes.
  • int $offset: the offset. The byte found at the offset will be returned as an integer. The must be at least one byte available at offset.
bytesToShort (line 174)

Extract an unsigned short from bytes.

  • return: the unsigned short found at offset, e.g., an integer in the range 0 to 65535.
  • static:
int bytesToShort (string &$bytes, int $offset, PelByteOrder $endian)
  • string &$bytes: the bytes.
  • int $offset: the offset. The short found at the offset will be returned as an integer. There must be at least two bytes available beginning at the offset given.
  • PelByteOrder $endian: one of LITTLE_ENDIAN and BIG_ENDIAN.
bytesToSLong (line 252)

Extract a signed long from bytes.

  • return: the signed long found at offset, e.g., an integer in the range -2147483648 to 2147483647.
  • static:
int bytesToSLong (string &$bytes, int $offset, PelByteOrder $endian)
  • string &$bytes: the bytes.
  • int $offset: the offset. The long found at offset will be returned as an integer. There must be at least four bytes available beginning at the offset given.
  • PelByteOrder $endian: one of LITTLE_ENDIAN and BIG_ENDIAN.
bytesToSRational (line 297)

Extract a signed rational from bytes.

  • return: the signed rational found at offset, e.g., an array with two integers in the range -2147483648 to 2147483647.
  • static:
array bytesToSRational (string &$bytes, int $offset, PelByteOrder $endian)
  • string &$bytes: the bytes.
  • int $offset: the offset. The rational found at offset will be returned as an array. There must be at least eight bytes available beginning at the offset given.
  • PelByteOrder $endian: one of LITTLE_ENDIAN and BIG_ENDIAN.
bytesToSShort (line 199)

Extract a signed short from bytes.

  • return: the signed byte found at offset, e.g., an integer in the range -32768 to 32767.
  • static:
int bytesToSShort (string &$bytes, int $offset, PelByteOrder $endian)
  • string &$bytes: the bytes.
  • int $offset: the offset. The short found at offset will be returned as an integer. There must be at least two bytes available beginning at the offset given.
  • PelByteOrder $endian: one of LITTLE_ENDIAN and BIG_ENDIAN.
longToBytes (line 107)

Convert a long into two bytes.

  • return: the bytes representing the long.
  • static:
string longToBytes (int $value, PelByteOrder $endian)
  • int $value: the long that will be converted. The lower four bytes will be extracted regardless of the actual size passed.
  • PelByteOrder $endian: one of LITTLE_ENDIAN and BIG_ENDIAN.
shortToBytes (line 88)

Convert a short into two bytes.

  • return: the bytes representing the short.
  • static:
string shortToBytes (int $value, PelByteOrder $endian)
  • int $value: the short that will be converted. The lower two bytes will be extracted regardless of the actual size passed.
  • PelByteOrder $endian: one of LITTLE_ENDIAN and BIG_ENDIAN.
Class Constants
BIG_ENDIAN = false (line 74)

Big-endian byte order.

Data stored in big-endian byte order store the most significant byte first, so the number 0x12345678 becomes 0x12 0x34 0x56 0x78 when stored with big-endian byte order.

LITTLE_ENDIAN = true (line 65)

Little-endian byte order.

Data stored in little-endian byte order store the least significant byte first, so the number 0x12345678 becomes 0x78 0x56 0x34 0x12 when stored with little-endian byte order.

SourceForge.net Logo Documentation generated on Wed, 21 Jul 2004 19:12:55 +0200 by phpDocumentor 1.3.0RC3