XOR handler

MWScript doesn't have a bitwise XOR function, but it does have an AND with ones-complement function in ClearFlag, which provides a bitwise NOT, which can be used with TestFlags (which is bitwise AND) to do a NAND. Thus you can use these to implement a 32-bit XOR.

on NAND(a, b)
    return ClearFlag(#FFFFFFFF, TestFlags(a, b))

on XOR(a, b)
    return NAND(NAND(a, NAND(a, b)), NAND(b, NAND(a, b)))

on Load
    let x = xor(#FFFF00FF, #8000FF55)
    syslog(NumToText(x, NumFormHex32))
Posted in MWScript, Sample Code | Comments Off on XOR handler