This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Hex manipulation
#8
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:
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
Reply


Messages In This Thread
Hex manipulation - by buuuudzik - 18.09.2016, 14:35
RE: Hex manipulation - by Erwin van der Zwart - 18.09.2016, 21:31
RE: Hex manipulation - by buuuudzik - 19.09.2016, 12:12
RE: Hex manipulation - by Erwin van der Zwart - 19.09.2016, 12:42
RE: Hex manipulation - by admin - 19.09.2016, 12:44
RE: Hex manipulation - by buuuudzik - 19.09.2016, 13:36
RE: Hex manipulation - by Erwin van der Zwart - 19.09.2016, 15:04
RE: Hex manipulation - by admin - 19.09.2016, 15:07
RE: Hex manipulation - by buuuudzik - 19.09.2016, 16:15

Forum Jump: