11
The world of art is full of colour, but the world of the network is even fuller than the world of art of diferent colours and it's renderings. That's why we need to know how to convert one type of colour format to another.
The challenge is self-evident:
Write a program / function than converts an given HEX code (#00ff0080
, for instance) to RGBA (like rgba(0, 255, 0, 0.5)
).
Rules:
- External libraries/ built-ins for converting HEX to RGBA are disallowed. However, jQuery and syntax replacers like that are acceptable.
- Standard Input/Output rules apply.
- Format of the alpha can be between (1 == 100%) or the other (100 == 100%) that's not really important.
- The output is flexible, as long as it returns the 4 converted values (as a String, Array, List, your choice).
- You may choose to take the input without the
#
in the beginning. Hence, you can take input as either#RRGGBBAA
orRRGGBBAA
. You can assume that the hex code (excluding the#
) will always be 8 characters long. - You should divide all the values by 255, including the alpha. The minimum decimal precision (for the alpha will be 2 decimal places).
Test Cases
Input: 00ff0080
Output: 0, 255, 0, 0.5
Scoring
code-golf, the code with the least amount of bytes wins.
Comments are not for extended discussion; this conversation has been moved to chat.
– Dennis – 2017-06-30T18:57:40.3371Are we required to take the "hex code" as a string? You say that we can take it without the leading
#
, in which case it would just be a 32-bit integer value. Is it legal to take it as that? – Cody Gray – 2017-07-10T16:06:54.580