Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: concatenate 3 HEX values to RGB?

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    7

    Question 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. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,040
    int color = (redval << 16) | (greenval << 8) | (blueval);

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    7
    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"
    Last edited by Swift Curse; 02-17-2013 at 07:03 AM.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,040
    I do not understand exactly what you need.

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    7
    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. #6
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    4,323

    Cool

    I would imagine:

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

Tags for this Thread

Posting Permissions

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