19.09.2016, 15:07
Of course second one does not work because '7F' == string.char(0x37, 0x46). If you want to send hex string as binary you have to convert it using lmcore.hextostr(str, true) or use string.char.
If by inversion you mean binary XOR, then your function should look like this:
If by inversion you mean binary XOR, then your function should look like this:
Code:
function convert(str)
local res, byte
res = ''
-- discard last 2 bytes
for i = 1, #str - 2 do
-- get single byte
byte = str:byte(i, i)
-- invert
byte = bit.bxor(byte, 0xFF)
-- add to result
res = res .. string.char(byte)
end
return res
end