0
Why does this work?
https://code.sololearn.com/c4zqu5sVICTd/?ref=app In order to calculate the hex value, I have to divide the rgb code numbers by 16 for the first hex number/letter, then take the remainder and multiply by 16 for the second. (Full explanation through website in code) So, my guess for the second number/letter was (rgb%16)*16. But in code this doesn't work and it's only rgb%16. Why?
1 Answer
+ 1
Compare how you would get digits from a 2-digit number in base 10.
Given 65 as the number:
left digit = (int) 65/10 = 6
right digit = 65%10 = 5
You wouldn't multiply 5*10 afterward.
Understand that the modulo operator evaluates to the integer remainder after whole number division. It is equivalent to 65 - (int)(65/10)*10 = 5.