Reputation: 215
I calculated there to be 16,777,216 possible hex color code combinations.
The maximum possible characters that we can have in a single hexadecimal character is 16 and the maximum possible characters a hex color code can contain is 6, and this brought me to my conclusion of 16^6.
Is this correct? If not, please tell me how many possible color combinations there are and how it can be worked out.
Upvotes: 19
Views: 32413
Reputation: 106
yes it's true I make a simple node program return an array of all the possible hex code here is the code
function getColors(){
var hexCode = [0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E' ,'F'];
var arr = [];
for (var i = 0; i < hexCode.length; i++) {
console.log(`i done it ${i+1} times`);
for (var y = 0; y < hexCode.length; y++) {
for (var x = 0; x < hexCode.length; x++) {
for (var a = 0; a < hexCode.length; a++) {
for (var b = 0; b < hexCode.length; b++) {
for (var c = 0; c < hexCode.length; c++) {
arr.push(`#${hexCode[i]}${hexCode[y]}${hexCode[x]}${hexCode[a]}${hexCode[b]}${hexCode[c]}\n`);
}
}
}
}
}
}
return arr;
}
var colors = getColors();
console.log(colors.length);
However when I run it, it logs to the console : 16 777 216.
Upvotes: 6
Reputation: 19
Well, I think it's 16777216 to, because my hexadecimal converter said that ffffff was 16777215. ffffff is the highest hexadecimal color code, so that would make 16777215. However, there is also 000000, which makes the answer 16777216, since it did not include 000000. Whoever typed that it was 16777216, you're right.
Upvotes: -1
Reputation: 335
There are 2 ways to write a color. RGB (rgb(R,G,B)) which has a range of 0-255 for red, green and blue. The Second way is hexadecimal (#RRGGBB).
In Hexadecimal there are 6 digits in total with 2 digits for each color. The maximum 2 digit value in hexadecimal is FF which in base 10 is 255.
If you think about it. RGB and HEX are similar in a way that allows you to enter 3 numbers for a Red, Green and Blue value. And the maximum value for each number is 255.
The maximum value for 6 hexadecimal digits in base 10 is 16,777,215. If you also add #000000 you get 16,777,216 as the total number of possible color combinations.
If we use RGB, the range of colors is 0-255. Meaning there are 256 possible values for each Red, Green and Blue. 256^3 is 16,777,216.
Therefore, the answer to your question is 16,777,216. No matter which way you count it.
Upvotes: 0
Reputation: 321
There are currently 184,549,376 possible color combinations in the rgba() color system, which is
R: 0 to 255 (256 values) ×
G: 0 to 255 (256 values) ×
B: 0 to 255 (256 values) ×
A: 0.0 to 1.0 (11 values)
Upvotes: 0
Reputation: 3533
There are 16,777,216 colors using #RRGGBB notation.
Each color channel is described using 1 byte of information. Byte can contain 256 different values. So for 3 channels, it's:
256^3 = 16,777,216 = 16M
However, modern browsers support transparency - #AARRGGBB, by similar logic you get:
256^4 = 4,294,967,296 = 4G
Upvotes: 23