I am reading a library ( github.com/adduc/phpmodbus ), and there is this function for converting integers to a string of little-endian or big-endian bytes:
private static function endianness($value, $endianness = 0) { if ($endianness == 0) return self::iecBYTE(($value >> 8) & 0x000000FF) . self::iecBYTE(($value & 0x000000FF)) . self::iecBYTE(($value >> 24) & 0x000000FF) . self::iecBYTE(($value >> 16) & 0x000000FF); else return self::iecBYTE(($value >> 24) & 0x000000FF) . self::iecBYTE(($value >> 16) & 0x000000FF) . self::iecBYTE(($value >> 8) & 0x000000FF) . self::iecBYTE(($value & 0x000000FF)); }
The iecBYTE function is just chr($value & 0xFF) .
Now, maybe I'm fat, but the line from the small end looks wrong.
For example, with 0xAABBCCDD you get {CC}{DD}{AA}{BB} .
I even watched it on Wikipedia. Shouldn't it be {DD}{CC}{BB}{AA} ?
The code works , although it really bothers me. Am I misunderstanding this correctly?
source share