+ 1
~ Beginner Project ~
Today I made something for myself that I think would be a fun project for beginners. Make a program to convert a color rgb value to its Hexadecimal equivalent. Example - Purple rgb=(255,0,255) hex=#FF00FF Check comment for Tips
2 ответов
+ 2
One main point is to convert one single decimal number (between 0 and 255) to its hex value. You could perform num%16 to get the last hex digit, and (num-num/16)%16 for the first one. You should take into account that 10->A, 11->B, ..., 15->F.
+ 1
purple-
red=255
green=0
blue=255
the Hexadecimal is made up of 2 values for each of those colors.
FF00FF
to get the first value, or F, divide red(255) by 16. This gives us 15.9375. Take the whole number, 15. this is our first value. This is where the letters come in. Numbers of 10-15 are represented by the letters A-F. so 10=A 11=B 12=C 13=D 14=E 15=F.
So our first value is F
This leaves us a decimal of .9375.. To get our second number we multiply this number by 16. this one results in 15 also, thus the second F