Trying to convert a Color value to?

I want to perform a logical XOR with one color to produce another color. The multitude of functions dealing with html, rgb, binary conversions has my head spinning. In order to do a mathematical XOR, I must be dealing in numerical values, and I’m confused about what kind of results of functions will support this. Everything I’ve tried so far gives me a zero result that I know is not correct.

For example, I have a form object that is a rectangle of a given color, say “00FF00” (green). If I XOR it with the value “FFFFFF” it will flip every bit in the original, yielding “FF00FF”. This trivial example is easily solved without math, but I want to be able to take any original color and XOR it with any 3 byte value and see what I get. I just don’t know what format I need to use in my arguments to make it actually work, and produce a value that I can plug into a color parameter in some object.

Basically like this: NewColor = OldColor XOR MyMask.

The documentation for xor just talks about doing boolean operations with it, but I have confirmed that it does indeed perform bitwise binary operations on a value, which is what I want to do with that big color-defining number to yield a different color-defining number.

Assuming OldColor and MyMask are each 6 characters of text.

NewColer = hexstr(hex(OldColor) xor hex(MyMask))[-6,-1]

By the way, AND, OR, and NOT also perform bitwise binary operations on integers. That’s why true() is -1 rather than 1. NOT -1 is 0 (false), but NOT 1 is -2 (also true).

Dave’s answer will work, but I’m wondering why you want to XOR a color. That really doesn’t give you anything meaningful.

I would think a better thing to do would be to convert the color to HSB values, then you could do things like shift the hue by 180", or make it 20% brighter or dimmer.

I’m doing some color experiments, not trying to doll up a form (yet). The value (i.e., bit placement) of the Mask variable has a big (adventurous) effect.

I did finally work out an algorithm for this, but Dave as usual came through with a much more elegant approach, thank you very much.