Sign in to follow this  
Followers 0
ravenfyre

Hex Function Not Converting Properly?

4 posts in this topic

#1 ·  Posted (edited)

I'm pretty sure it's user error as autoit spy seems to get it right ^^.

I'm trying create converter script to convert my old decimal values to new ones for use with PixelColor. It's seems rather simple, yet sometimes it doesn't work.

This is what it does,

1) converts old decimal to hex

2) switches hex values around, eg BGR-AABBCC to RGB-CCBBAA

3) converts it back to decimal

Well it sometimes but with some decimal values it seems to have problems. Consider this example.

THIS IS RIGHT - taken from autoitspy

RGB - D1DCEB - 13753579

BGR - EBDCD1 - 1545748

Now here is where I think I'm messing up although I don't know why.

THIS IS WRONGB] - converted with autoit script

Hex(1545748, 6)) = 179614 <-????? what's this? It should be EBDCD1 as seen above

However if the decimal value is 8 digits, it actually converts correctly but with 7 it messes up. Why is this?

Edited by ravenfyre

Share this post


Link to post
Share on other sites



1545748 = 0x179414

(so that is correct. I tested this with my calculator, and by hand, so I am sure this is valid.)

0xD1DCEB = 13753579

0xEBDCD1 = 15457489

I think you just missed the 9 on the end of that number from the spy.


[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

RGB - D1DCEB - 13753579

BGR - EBDCD1 - 1545748

<{POST_SNAPBACK}>

I also wanted to point out a good way to eyeball these kinds of mistakes. Please note that the first number of the first hex number is D, and the first number of the 2nd hex number is E. E > D, so the 2nd number will end up larger than the first. Seeing as how your decimal converstion is clearly lower (as it has less digits) you can know right away that you made an error.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

oops lol you're right I did miss the 9. Talk about user error ^^.

So anyway I made my quicky conversion script. An easy way to get the new decimal values from the old one. Seems to be working right =).

$input = InputBox("Input", "Enter old decimal value", "", "", -1, -1, 0, 0);

$hexold = Hex($input, 6)

$readstart = StringMid ($hexold, 1,2);
$readmid = StringMid ($hexold, 3,2);
$readend = StringMid ($hexold, 5,2);

$hexnew = $readend&$readmid&$readstart;

$decnew = Dec($hexnew);

MsgBox(0,"Conversion", "New Hex: "&$hexnew&@CRLF&"New Dec: "&$decnew)

ClipPut ($decnew);
Edited by ravenfyre

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0