# need help fig out algorithm

This topic is 4753 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

ok suppose I want to list the hex values of the 2.5 million colors that there are, in order. (I wish to create a database where each row contains a hex color value), can anyone help me figure out the algorithm? Also, how many possible colors are there in the PC?

##### Share on other sites
Well in 24 bits there are 2^24 = 16777216 colors ranging from 000000 to FFFFFF in hex. It sounds like you want to sort these somehow? Of course they have an obvious order, simply treat them as a single 24 bit integer. Other options would be to sort by hue or brightness, take a look at the color picker in your favorite graphics app for ideas.

##### Share on other sites
well I need to generate the hex values for all of them. I think I got it by now though by using 6 nested if statements, each one ranging from 0 - F.

oh by the way, 2^24 is in binary, but how would I represent that equation in hex?

##### Share on other sites
Quote:
 Original post by Kommi10well I need to generate the hex values for all of them. I think I got it by now though by using 6 nested if statements, each one ranging from 0 - F.oh by the way, 2^24 is in binary, but how would I represent that equation in hex?

You mean F^6 ????

##### Share on other sites
Quote:
 well I need to generate the hex values for all of them. I think I got it by now though by using 6 nested if statements, each one ranging from 0 - F.

As in, output text using the characters '0' through '9' and 'A' through 'F', which represent those values written in hex? I assume you meant nested for-loops, to generate everything. Of course, you can also just do one loop over all the possible numeric values, and ask the IO library to do the numeric formatting for you. This should work:

cout << hex; // Tell the output stream to start writing numbers in hex, instead// of decimal (as it would by default).for (int i = 0; i < 16777216; i++) {  cout << i << endl;}

Quote:
 oh by the way, 2^24 is in binary, but how would I represent that equation in hex?

You're making a horrible mess of terminology, but if I understand you - 16^6. Of course, you knew that, because you had 6 nested loops. :)

##### Share on other sites
Quote:
 Original post by EascaYou mean F^6 ????

No, because 'F' is 15. [smile]

##### Share on other sites
Quote:
Original post by Zahlman
Quote:
 Original post by EascaYou mean F^6 ????

No, because 'F' is 15. [smile]

*cough* I was just *cough* testing you... [embarrass]