How can I convert colors from (N, N, N) format to #AABBCC (and #AAABBBCCC) ?
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
#FFFFFF, so simpleevery single char has
0..Frange. That is0..15. So two chars is0..(16*16-1) -> 0-255To convert between formats just think about:
#AABBCCare three valuesAA BB CC. Every single value represents a channel (red, green, blue) that can span from0to255or from0toFFor from0.0to1.0if you have for example #123456 you can do
in general a two digits hex number composed by
XYcan be converted to an decimal value by multiplyingXby 16 and addingY, taking care of converting digits that are over 9 (A, B, C, D, E, F) to their counterparts (10, 11, 12, 13, 14, 15). So for exampleACwould beA*16 + C = 10*16 + 12.(To be really precise a n digit hex number is converted by multiplying the i-th digit from right by 16^i and adding all of them together)