# opposite of a binary color? Answered

i want to find the opposite of a binary color value....i want an easy way prefferably...and yes, i searcher googl... o the binary is 22a61b

Tags:

## Discussions

The forums are retiring in 2021 and are now closed for new topics and comments.

In fact, I have just figured out that my complicated algorithm below is silly. The correct answer is really simple -- the visual complement to any RGB color is exactly the ones complement of that color code! So, for your example of 0x22a61b, the complement would be 0xffffff-0x22a61b = 0xdd59e4.

Look up "RGB color table" on Google (i.e., not "binary"). The hexadecimal (base sixteen) code you posted above, 0x22a61b, consists of three single-byte values: 0x22 is the red (on a scale from 0 to 0xff=255), 0xa6 is the green, and 0x1b is the blue.

To find the complementary ("opposite") color, you need to know some color theory and use a proper color wheel to find the coded color, identify its antipode, and then determine the RGB code for that result.

The basic theory for RGB is simple: each base color is the complement of the sum of the other two: R is complementary to G+B, G to R+B, and B to R+G. In terms of hex codes, this means:

0x000000 complements 0xffffff
0xff0000 complements 0x00ffff
0x00ff00 complements 0xff00ff
0x0000ff complements 0xffff00

For other intensities of the pure base colors, just take the ones-complement (== 0xff-value) of the color, and apply that to the other two; thus, a pale red 0x7f0000 would have the complementary value 0x008080 (since 0xff-0x7f = 0x80).

So far, so good. Unfortunately, for an arbitrary color mix as you have, you cannot just decompose it into the three primaries and complement them, since each complement has two components. You'd end up with a sum with entries above the maximum value of 0xff. As I noted above, you really need a color wheel (or some simple color software) to do this more complicated work for you.

In fact, I have just figured out that my complicated algorithm above is silly. The correct answer is really simple -- the visual complement to any RGB color is exactly the ones complement of that color code! So, for your example of 0x22a61b, the complement would be 0xffffff-0x22a61b = 0xdd59e4.