Home computickets Color translation to various number systems

Color translation to various number systems

Author

Date

Category

In the interview I was asked a question that I was less expected to hear, namely: “How to translate a color from 16-riche to a 10-richery system, while maintaining transparency, and vice versa?”

For example, such a #FFFFFFFFFFF format is translated into such a RGB (255, 255, 255) or in RGBA if transparency is present.

p.s. Actually a question in quotes.


Answer 1, Authority 100%

#FFFFFF format translate into such - RGB (255, 255, 255)

We take into account that each pair of six characters in #FFFFFF is a RGB color (Red, Green, Blue), i.e. #FFFFFF – & gt; #FF FF FF, then each symbol from a hexadecimal format is in its binary form, (value for f = 1111), and we get as a result:

11111111 111111111111111

then translate into the decimal system each of the three numbers, receiving:

255 255 255

Similarly, with a numeric display of transparency, if present.


Answer 2

The task is not specific for color – if you can translate from a 16-riche system to 10-richene and vice versa, then you can do it at least for flowers, at least for anything.

It’s like a multiplication table – it is alone, and there is no separate table to count apples, separate to count the cigarettes, etc.

This format – #FFFFFF is simply a brief form for recording three 16-riche numbers – (FF, FF, FF).
If you open any calculator program that can translate between the number systems, you will see that FF is 255.

If there is information about transparency in color, then there will be another number.
In the 16-riche system – FF, FF, FF, FF. That is, in a brief form – #FFFFFFFF

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions