Overview Package Tree | HessianPHP |
FRAMES NO FRAMES | |
SUMMARY: FIELD METHOD | DETAIL: FIELD METHOD |
HessianPHP.Protocol.ByteUtils
class ByteUtils
This is a helper class designed to work with byte conversion and representation of numbers
Field Summary |
---|
Method Summary |
---|
public string | getIntBytes Generates big endian byte representation of a number with a defined precision, 16 or 64 bits for example, default 32 bits. |
public string | getFloatBytes Returns a string with the byte representation of a IEEE 754 double in 64 bit precision. |
public boolean | isLittleEndian Test if this machine is a little endian architecture |
public string | orderedByteString Returns a sequence of bytes in big endian order, it orders the string depending on machine architecture (big endian or little endian). |
Method Detail |
---|
public string getIntBytes(long number, int precision = 32)
Generates big endian byte representation of a number with a defined precision, 16 or 64 bits for example, default 32 bits.
This function is equivalent to do the transformation by hand with a fixed bit precision, as in (for a 32 bit representation):
$b32 = $value >> 24;
$b24 = ($value >> 16) & 0x000000FF;
$b16 = ($value >> 8) & 0x000000FF;
$b8 = $value & 0x000000FF;
$bytes .= pack('c',$b32);
$bytes .= pack('c',$b24);
$bytes .= pack('c',$b16);
$bytes .= pack('c',$b8);
number
- number to be transformed precision
- precision public string getFloatBytes(double number)
Returns a string with the byte representation of a IEEE 754 double in 64 bit precision.
Works fine between PHP clients and servers but it uses a machine dependent byte packing representation (pack format "d"). WARNING: Due to incompatible double formats among different machines, this function is not guaranteed to return the number with extreme accuracy, specially with periodic fractions such as 1.3333... Take this in account.
number
- number to be transformed public boolean isLittleEndian()
Test if this machine is a little endian architecture
Based in code from Open Sound Control (OSC) Client Library for PHP
Author: Andy W Schmeder <andy@a2hd.com>
Copyright 2003
public string orderedByteString(string string)
Returns a sequence of bytes in big endian order, it orders the string depending on machine architecture (big endian or little endian).
Based in code from Open Sound Control (OSC) Client Library for PHP
Author: Andy W Schmeder <andy@a2hd.com>
Copyright 2003
string
- sequence of bytes to order Overview Package Tree | HessianPHP |
FRAMES NO FRAMES | |
SUMMARY: FIELD METHOD | DETAIL: FIELD METHOD |