while IN>0 do\r
I=I+1\r
IN , D = math.floor(IN/B), math.modf(IN,B)+1\r
- OUT=string.sub(K,D,D)..OUT\r
+ OUT = string.sub(K,D,D)..OUT\r
end\r
return OUT\r
end,\r
end\r
local s={}\r
for i = 1, #(bytes) do\r
- s[i] = string.format("%02X",bytes[i]) \r
+ s[i] = string.format("%02X",bytes[i]) \r
end\r
return table.concat(s)\r
end, \r
return table.concat(t) \r
end,\r
\r
+ Chars2num = function(s)\r
+ return (s:byte(1)*16777216)+(s:byte(2)*65536)+(s:byte(3)*256)+(s:byte(4))\r
+ end,\r
+ \r
+ -- use length of string to determine 8,16,32,64 bits\r
+ bytes_to_int = function(str,endian,signed) \r
+ local t={str:byte(1,-1)}\r
+ if endian=="big" then --reverse bytes\r
+ local tt={}\r
+ for k=1,#t do\r
+ tt[#t-k+1]=t[k]\r
+ end\r
+ t=tt\r
+ end\r
+ local n=0\r
+ for k=1,#t do\r
+ n=n+t[k]*2^((k-1)*8)\r
+ end\r
+ if signed then\r
+ n = (n > 2^(#t*8-1) -1) and (n - 2^(#t*8)) or n -- if last bit set, negative.\r
+ end\r
+ return n\r
+ end,\r
+ \r
-- function convertStringToBytes(str)\r
-- local bytes = {}\r
-- local strLength = string.len(str)\r