# inverse hex codes

#### Bear_2759

Joined May 23, 2008
120
hey guys, so I bought myself an arduino uno R3 and a nokia 6100 LCD shield to play with and learn a bit about programming. first thing I've had to do though and almost done, is re-write the driver lol. for the most part it's done, but now I need to know if anyone can tell me a site that'll have inverted 12bit hex colour codes. I've been searching but cant find anything. or is there an easy way to invert?

something like this http://rangevoting.org/ColorCode.html
but inverted. it took me a while to clue into it and decided to swap black and white in the driver and now they work fine. so have to invert all the other colours that're declared there and also any other colours set by hex code elsewhere

Joined Nov 28, 2011
57
hey guys, so I bought myself an arduino uno R3 and a nokia 6100 LCD shield to play with and learn a bit about programming. first thing I've had to do though and almost done, is re-write the driver lol. for the most part it's done, but now I need to know if anyone can tell me a site that'll have inverted 12bit hex colour codes. I've been searching but cant find anything. or is there an easy way to invert?
Sorry if I'm misunderstandingbut you just need to invert the bits, right? Hex 000 becomes FFF, etc? One's complement in C is the tilde character (~).

#### Bear_2759

Joined May 23, 2008
120
that worked, thanks. now that some of the colours are appearing correctly on screen, I've got another issue. the only colours that are apparing correctly are pink, red, white and black. everything else appears as one of those 4. I'm tempted to re-write the whole driver but for a noob this would be a big job.

#### Bear_2759

Joined May 23, 2008
120
getting closer, re-writing the drivers wasn't quite as complex as I thought it would be since I had a refrence driver to go off. I did find an inversion command that was switched on, turning this off half solved my issue.

now some colours are appearing correctly, but reds and blues appear to be swapped. for example, take the last table on this page http://www.december.com/html/spec/color3hex4.html
F00 through to F0F. if I just have a whole lot of LCDClear(colour) commands one after the other so it scales through them all, it starts as BLUE instead of red and ends up at fuchsia. same if I went with one of the tables that had blue in it, it'd start at red.

any ideas? I think I'm going to be stuck with this one, and if I dont find an answer I'll be stuck with experimenting with hex codes till I find the colours I want.

Joined Nov 28, 2011
57
...now some colours are appearing correctly, but reds and blues appear to be swapped. for example, take the last table on this page http://www.december.com/html/spec/color3hex4.html
F00 through to F0F. if I just have a whole lot of LCDClear(colour) commands one after the other so it scales through them all, it starts as BLUE instead of red and ends up at fuchsia. same if I went with one of the tables that had blue in it, it'd start at red.

any ideas?
So it seems you need to swap the first and third nibble? In C, try something like...

Rich (BB code):
  colorVal = ((colorVal & 0x0f) << 8) | (colorVal & 0xf0) | ((colorVal >> 8) & 0x0f);

#### Bear_2759

Joined May 23, 2008
120
thanks for that, I'll give it a go when I get home. so I understand it better, and am able to experiment can you explain what it does a bit?

Joined Nov 28, 2011
57
thanks for that, I'll give it a go when I get home. so I understand it better, and am able to experiment can you explain what it does a bit?
Sure. Say that the variable colorVal holds (hexadecimal) 0ABC. Let's break the code into three parts:

First, "((colorVal & 0x0f) << 8)": this says take 0ABC and "&" (bit-wise AND) it with 000f, which results in masking off everything except the lower 4-bit nibble, resulting in 000C, then shift it left 8 bits to end up with 0C00.

Second, "(colorVal & 0xf0)" masks that same value (0ABC) with 00f0 to yield 00B0.

Third, "((colorVal >> 8) & 0x0f)" shifts 0ABC right 8 bits to yield 000A (at this point it's likely we don't need to mask it with "& 0X0f", but it doesn't hurt, and I included it in case the high nibble isn't zeroI don't know for certain what you're starting with).

Those three sections are combined with the "|" (bit-wise OR) operators0C00 | 00B0 | 0A00 yields 0CBA. ("+" would work fine too.)