Need to encode & decode byte-stream (containing non-ascii characters possibly), from/into uint16, uint32, uint64 (their typical C/C++ meaning), taking care of endianness
my suggestion for an "Int16ToByte"-function without checking of parameters:
function Int16ToBytes(num, endian)
if num < 0 then
num = num & 0xFFFF
end
highByte = (num & 0xFF00) >> 8
lowByte = num & 0xFF
if endian == "little" then
lowByte, highByte = highByte, lowByte
end
return string.char(highByte,lowByte)
end