Sign in to follow this  
Kommi10

need help fig out algorithm

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Kommi10
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?

You mean F^6 ????

Share this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this