Skip to content

Logic Operators

ResIOT allows you to do operations on single Byte, or even on Bits with four logic operators AND, ANDNOT, OR, XOR.

This is an example of operations between two Bytes with AND and ANDNOT.

    byte1 = 0x24
    byte2 = 0x21

    -- byte1     0 0 1 0 0 1 0 0 = 0x24
    -- byte2     0 0 1 0 0 0 0 1 = 0x21
    -- finalByteAND 0 0 1 0 0 0 0 0 = 0x20
    finalByteAND = resiot_and(byte1, byte2)

    -- byte1           0 0 1 0 0 1 0 0 = 0x24
    -- byte2           0 0 1 0 0 0 0 1 = 0x21
    -- finalByteANDNOT 0 0 0 0 0 1 0 0 = 0x04
    finalByteANDNOT = resiot_andnot(byte1, byte2)

This, instead, with OR and XOR

    byte1 = 0x10
    byte2 = 0x19

    -- byte1        0 0 0 1 0 0 0 0 = 0x10
    -- byte2        0 0 0 1 1 0 0 1 = 0x19
    -- finalByteOR  0 0 1 0 0 0 0 1 = 0x21
    finalByteOR = resiot_or(byte1, byte2)

    -- byte1        0 0 0 1 0 0 0 0 = 0x10
    -- byte2        0 0 0 1 1 0 0 1 = 0x19
    -- finalByteOR  0 0 0 0 1 0 0 1 = 0x09
    finalByteXOR = resiot_xor(byte1, byte2)

Note

ResIOT has a lua function used to read the single bit. Here's an example:
-- 0x19 | 00011001
-- result = false
result = resiot_readbit(0x19, 0)