I have a PHP class for reading Binary data that I'm converting to NodeJS or finding the equivalent of a couple functions in NodeJS. The functions I'm interested in this BinaryReader class are ReadULong
and ReadUShort
. I believe these mean read Unsigned Long integer (4 bytes) and Unsigned Short integer (2 bytes). As I'm trying to find the equivalent for these in NodeJS, I get confused on which function to use between these:
buf.readUInt16LE(offset, [noAssert])
buf.readUInt16BE(offset, [noAssert])
buf.readUInt32LE(offset, [noAssert])
buf.readUInt32BE(offset, [noAssert])
What would LE
or BE
stand for in this case?
The Buffer docs are located here but I was unable to find an explanation for those here.
Also I've found a constant on the PHP class that says const DEFAULT_BYTE_ORDER = 'L';
. Is this L
same as that L
in readUInt32LE
? Is this whole thing about Byte Orders?
So far I've read these articles:
- Good Source at cplusplus.com for looking up variable types.
- PHP bytewise tutorial and binary math
- How to read binary files byte by byte in Node.js question at stackoverflow
If I could be given a couple more references to read about binary reading that would be much appreciated!
BE and LE stand for big endian and little endian. In big endian, the most significant byte is stored in the smallest address, and in little endian, the least significant byte is stored in the smallest address. That being said, endian does indicate the byte order. You can see the pattern in one of the examples in the documentation: