Logic Machine Forum
Bit from 4-byte - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Bit from 4-byte (/showthread.php?tid=4488)



Bit from 4-byte - 2MAX - 11.01.2023

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)


RE: Bit from 4-byte - admin - 11.01.2023

What is the datatype of source object? What do you get when logging the value?
Code:
value = event.getvalue()
log(value)



RE: Bit from 4-byte - 2MAX - 11.01.2023

(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


RE: Bit from 4-byte - admin - 11.01.2023

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.


RE: Bit from 4-byte - 2MAX - 12.01.2023

(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