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.

Bit from 4-byte
#1
Hello,

i need extraxt every single of 32 bit from 4-byte
i try this scrip but something is wrong, because ist always FALSE on eaxh bit

value = event.getvalue()
function getbit(value, nr)
  value = bit.rshift(value, nr)
  return bit.band(value, 1)==1
end

bit0 = getbit(value,0)
log(bit0)
bit1 = getbit(value,1)
log(bit1)
.
.
.
.
bit32 = getbit(value,32)
log(bit32)
Reply
#2
What is the datatype of source object? What do you get when logging the value?
Code:
value = event.getvalue()
log(value)
Reply
#3
(11.01.2023, 13:00)admin Wrote: What is the datatype of source object? What do you get when logging the value?
Code:
value = event.getvalue()
log(value)

* number: 67108864
Reply
#4
Check the script carefully, might be copy-paste error there. For 67108864 only bit 26 will be true.
Also there's no bit 32, indexing starts from 0, the maximum bit is 31.
Reply
#5
(11.01.2023, 13:08)admin Wrote: Check the script carefully, might be copy-paste error there. For 67108864 only bit 26 will be true.
Also there's no bit 32, indexing starts from 0, the maximum bit is 31.

My mistake, its works fine. Thank you
Reply


Forum Jump: