Forum Rule: Always post complete source code & details to reproduce any issue!

# Thread: concatenate 3 HEX values to RGB?

1. ## concatenate 3 HEX values to RGB?

Im trying to concatenate three hex values(redval,greenval,blueval) into a RGB Value(0xFFFFFF) is this possible? I've been trying for a while and it just wont work...(i already googled for help and still couldn't find anyone who has successfully done it.

2. int color = (redval << 16) | (greenval << 8) | (blueval);

3. ummm seems to out put just a number from 0-255.

perhaps how im converting to hex isnt right?
redval = (redval, HEX);
ah its not right its just giving the value of "16"

4. I do not understand exactly what you need.

5. okay so here is what i have.

I have three potentiometer each with a integer variable(redval,greenval,blueval) with a value between 0-255.
What i want to do is turn these three variables into a color code( ie. 0x00FF00 or 0xFFFFFF) that is represented by the potentiometers.

Does that explain it better?

6. I would imagine:

Code:
```unsigned long color_code;
// ...
color_code = ((((unsigned long)(redval & 0xff)) << 16)
| (((unsigned long)(greenval & 0xff)) << 8)
| ((unsigned long)(blueval & 0xff)));```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•