21.09.2018, 11:40
(21.09.2018, 10:54)admin Wrote: You can access any value up to 4 bytes the same way. Second argument for getbit function is bit number (starting from 0, up to 31).
You can also access bytes separately by using the code from the first example:
Code:12345678910111213141516171819202122232425262728293031hex = event.datahex bytes = {} for i = 1, #hex, 2 do bytes[ #bytes + 1 ] = tonumber(hex:sub(i, i + 1), 16) end function getbit(value, nr) value = bit.rshift(value, nr) return bit.band(value, 1) end -- first byte grp.checkupdate('32/1/1', getbit(bytes[ 1 ], 0)) grp.checkupdate('32/1/2', getbit(bytes[ 1 ], 1)) grp.checkupdate('32/1/3', getbit(bytes[ 1 ], 2)) grp.checkupdate('32/1/4', getbit(bytes[ 1 ], 3)) grp.checkupdate('32/1/5', getbit(bytes[ 1 ], 4)) grp.checkupdate('32/1/6', getbit(bytes[ 1 ], 5)) grp.checkupdate('32/1/7', getbit(bytes[ 1 ], 6)) grp.checkupdate('32/1/8', getbit(bytes[ 1 ], 7)) -- second byte grp.checkupdate('32/2/1', getbit(bytes[ 2 ], 0)) grp.checkupdate('32/2/2', getbit(bytes[ 2 ], 1)) grp.checkupdate('32/2/3', getbit(bytes[ 2 ], 2)) grp.checkupdate('32/2/4', getbit(bytes[ 2 ], 3)) grp.checkupdate('32/2/5', getbit(bytes[ 2 ], 4)) grp.checkupdate('32/2/6', getbit(bytes[ 2 ], 5)) grp.checkupdate('32/2/7', getbit(bytes[ 2 ], 6)) grp.checkupdate('32/2/8', getbit(bytes[ 2 ], 7))
Thank you again for the great support. Excellent!!!

