Jump to content

Recommended Posts

Posted

For some reason, I can't convert to Hex a Decimal color that has been calculated.

For example, this works:

Local $iColor = 3310546
ConsoleWrite("$iColor (dec): " & $iColor & ", $iColor (hex): " & Hex($iColor, 6) & @CRLF)

giving the expected output:

$iColor (dec): 3310546, $iColor (hex): 3283D2

But if I want to take an average of several colors, I have a problem.  For example this doesn't work:

$iColor = (3310546 + 3310546) / 2
ConsoleWrite("$iColor (dec): " & $iColor & ", $iColor (hex): " & Hex($iColor, 6) & @CRLF)

giving the wrong output:

$iColor (dec): 3310546, $iColor (hex): 000000

I observe this behavior after any processing of a decimal color.

Is this a bug?

Posted
9 minutes ago, jmor said:

Is this a bug?

No.  After your calculation, $iColor's data type is a double not an integer. They are stored differently in memory.  The Hex function did exactly what you told it to do,  Maybe the example below will help illuminate the issue:

 

$iColor = (3310546 + 3310546) / 2
ConsoleWrite("$iColor is a " & VarGetType($iColor) & @CRLF)
ConsoleWrite("$iColor = 0x" & Hex($iColor) & @CRLF)
ConsoleWrite("$iColor (dec): " & $iColor & ", $iColor (hex): " & Hex($iColor, 6) & @CRLF)

ConsoleWrite(@CRLF)

$iColor = Int((3310546 + 3310546) / 2)
ConsoleWrite("$iColor is a " & VarGetType($iColor) & @CRLF)
ConsoleWrite("$iColor = 0x" & Hex($iColor) & @CRLF)
ConsoleWrite("$iColor (dec): " & $iColor & ", $iColor (hex): " & Hex($iColor, 6) & @CRLF)

Console

$iColor is a Double
$iColor = 0x414941E900000000
$iColor (dec): 3310546, $iColor (hex): 000000

$iColor is a Int32
$iColor = 0x003283D2
$iColor (dec): 3310546, $iColor (hex): 3283D2

 

Posted

Many thanks for this excellent and prompt clarification.

I am still discovering Autoit and hadn't found the Int() conversion (I had found Number() but that was'nt the solution).

This response solves my problem😊

Posted

just some FYI
the 6 digits of hex color abcdef are actually - (ab) = red, (cd) = green, (ef) = blue
and converted to decimal = each pairs' correlation to 0-255 of each R - G - B

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...