Gray color with hex shorthand between #fff and #eee

Hi,

Do you know of any gray color tones that can be represented via hex code shorthand (3 characters) between #fff and #eee? For example, I like the tone of #f1f1f1 but it can’t be written in shorthand format.

Thanks.

There are no letters between ‘e’ and ‘f’, so no, you would need 6 characters.

1 Like

I didn’t quite understand your reasoning, but thanks anyway. Is there a way (a script perhaps) to find the closest shorthand color code to a given code? I mean, I want a color that can be represented in shorthand format, which is close to a color I have (e.g. 067ec9). It is a blue tone, so, I want a blue tone close to that color, which can be represented in shorthand format, how can I find that?

I’m sure it would be possible to write a script. If we take your example

067ec9

The first pair (06) is between 00 and 11, and is closer to 00 (or 0 in shorthand notation)

7e is closest to 77 (7), and c9 is closest to cc (c), so you would end up with 07c.

1 Like

Can you explain what is meant by “shorthand color code”?

Perhaps this web page may be helpful:

Thank you very much for the concept! I sure can write a script for that and this will help me achieve what I want.

I don’t know if I used wrong wording, but shorthand color code is #fff, for full color code #fffff, likewise, #07c for #0077cc.

1 Like

If you’re using script to derive a color between two colors it might be easier to work with RBG values (0 - 255) instead of hex (00 - ff)

The thing is, my purpose is to derive a color (output) that is the closest color to another color (input), which can be represented as shorthand hex code. I couldn’t think of how RBG would work for that, but thanks anyway.

Yes, it would be easier to do calculations in RGB, rounding things off to the nearest 16, you could then convert back to hex at the end.

There are exactly 14 shades of gray between white (#fff) and black (#000) using three character HEX “shorthand”. No more and no less. If you come up with 15 or more, you are no longer using 3 character HEX colors.

If you want to use the nearest HEX shade of gray to represent a 6 character HEX color or RGB color, then the gray that you are seeking is the nearest approximation to the color.

You can extend the range of shades of gray to 254 by using 6 character HEX or RGB.

Yes, that is like asking if there is an integer between 2 and 3. There can’t be.

By using only shorthand, it is effectively like using a lower bit-depth for colour. So RGB values have a range of just 0 - 15, instead of 0 - 255. This will offer the 14 shades of neutral grey. If you are wanting tinted grey, it’s possible, but similarly limited by the lower bit depth available, hence you will only get the closest approximation of a colour that can only be defined with long-hand.

1 Like

simply put. it’s mathematically imposible.
All tones of gray are generated when all 3 color channels (r,g,b) are the same.
in hex, each pair of letters represents a channel respectively: rrggbbb.

In shorthand the information is “rounded off” which limits the possible colors. so you only have 16 available tones on a “color" as opposed to 256.

Hope that clears things up :slight_smile:

Let’s say I have my input color as (R, G, B) = (100, 80, 90). What is the closest RGB color to this color that can be written as shorthand hex?

I must say, whether you do the maths in hex or decimal is of little consequence. Your algorithm is going to need to determine which of the following is closest to each of the red, green and blue values. My brain isn’t up to this today, I’m afraid.

0 17 34 51 68 85 102 119 136 153 170 187 204 221 238 255

1 Like

Thanks, that’s enough for me to write the script. Initially, I did it based on

0 16 32 48 …

which didn’t give the correct result.

1 Like

To do it mathematically, you would do this calculation:-

100 / 255 = 0.392
80 / 255 = 0.314
90 / 255 = 0.353

That gives you a decimal value (range 0 - 1). Then:-

0.392 * 16 = 6.272
0.314 * 16 = 5.024
0.353 * 16 = 5.648

Now round those to the nearest integer and you get:-

R = 6
G = 5
B = 6

This is a comparison between the original colour and the resulting rounded off colour.

3 Likes

Unless my brain is completely addled (which is a distinct possibility) I think the multiplier wants to be 15 rather than 16. Otherwise we would end up with e.g.

250 / 256 = 0.9766

0.9766 * 16 = 15.625

round(15.625) = 16

Yes, if 0 = 0, then 15 = F

But that will still make the divider 255, not 256 with 0 being the lowest value.

1 Like

Of course; my bad! The maths can then be simplified just by dividing by 17 since 255 / 15 = 17.

1 Like