At the interview, I was asked a question that I least expected to hear, namely: "How to translate color from hexadecimal to decimal numbering system, while maintaining transparency, and vice versa?".
For example, this format #ffffff translate into such - rgb(255, 255, 255) or rgba , if transparency is present.
ps actually a question in quotes.
2 answers
формат #ffffff перевести в такой - rgb(255, 255, 255)
We take into account that each pair of six characters in #ffffff is an RGB color (red, green, blue), i.e. #ffffff -> #ff ff ff, then we represent each character from the hexadecimal format in its binary form (value for f = 1111), and we get the result:
11111111 11111111 111111111 Then we translate each of the three numbers into the decimal system, obtaining:
255 255 255 Similarly, with a numerical display of transparency, if present.
The task is not color-specific - if you can translate from a 16-tric system to a 10-tier system and vice versa, then you can do it even for colors, at least for anything.
It’s like a multiplication table — it’s one, and there’s no separate table for counting apples, a separate one for counting cigarette butts, and so on.
This format - #ffffff is just a short form for writing three hexadecimal numbers - (ff, ff, ff). If you open any calculator program that can translate between number systems, you will see that ff is 255.
If there is transparency information in color, then there will be another number. In the hexadecimal system - ff, ff, ff, ff. That is, in short form - #ffffffff
#ffffffff- here the first 2 are transparency. - Artem Gorlachev