Toggle a Bit

//  ToggleBit(value, bitNumber)
//  Examples:
//      Printf "0x%X\r", ToggleBit(0xFFFF,0)        // Prints 0xFFFE
//      Printf "0x%X\r", ToggleBit(0xFFFE,0)        // Prints 0xFFFF
//  Requires Igor Pro 7.00 or later.
Function ToggleBit(int value, int bitNumber)
    int bitMask = 1 << bitNumber        // << requires Igor Pro 7 or later
   
    if ((value & bitMask) != 0)
        // Bit is set - clear it
        value = value & ~bitMask
    else
        // Bit is cleared - set it
        value = value | bitMask
    endif
   
    return value
End

 

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More