-3

I'm having trouble understanding this converting from hex to int and int to hex. How does the value 6713707 or 6,713,707 equal 0x66716b? How does one go from one to the other?

This is what I see in my debugger:

enter image description here

If I add the red, green and blue together I get:

102 + 113 + 107 = 322;

If I multiply those three values I get:

102 * 113 * 107 = 1,233,282;

Where is the number 6713707 coming from? Can you show me your work?

Background:
I'm working with colors and in HTML and CSS you use #FF0000 to represent red. But in JavaScript and ActionScript when you access those colors they return as int and numbers.

1
  • "If I multiply those three values I get" --- and you multiply them because ...? When you have decimal 111 it's not equal to 1 * 1 * 1 for sure, but to 1 * 100 + 1 * 10 + 1 * 1
    – zerkms
    Dec 17, 2015 at 23:22

2 Answers 2

1

0x66716b is just the concatenation if the red (66), green (67) and blue (6b) hex values, 0x is a way of saying "this is hex not decimal" (which is why there are [0x##] values next to the decimal in your debugger)

I'm quite sure that 6713707 is what you get if you turn 66716b in hex to decimal, I.e. 1 x b (b=11) + 16 x 6 + 256 x 1 + 4096 x 7 + .... (I don't have a calculator to make certain/do the rest).

Hope I've helped!

0

The RGB values are three eight-bit values, which form the low 24 bits of a 32-bit value (the high eight bits are sometimes referred to as the "alpha channel"). So your full 32-bit hex value is 0x0066716b. Converting hex to decimal gives the value 6713707.

1
  • Can explain more how that works? I've seen the converters before. I want to see the work. Dec 17, 2015 at 23:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.