jmor Posted March 6, 2021 Posted March 6, 2021 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?
TheXman Posted March 6, 2021 Posted March 6, 2021 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 Musashi, Skysnake and FrancescoDiMuro 3 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
jmor Posted March 6, 2021 Author Posted March 6, 2021 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😊 TheXman 1
Shark007 Posted March 6, 2021 Posted March 6, 2021 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now