Sign in to follow this  
Followers 0
bienmexicano

need to convert from hexadecimal to decimal

10 posts in this topic

Hi guys i've been having a hard time figuring out how to convert from Hexadecimal to Decimal

my code is this

ConsoleWrite(Hex(2684354573)&@CRLF)
ConsoleWrite(Dec('A000000D')&@CRLF)

this program Should Write:

A000000D

2684354573

but the result is different:

A000000D

-1610612723

why is it that when i convert from Hex to decimal is so different that when i convert from hex to Decimal?

If Someone could help me out i would appreciate it

Thanx in advance


i love to draw so Go here!!!!!!!

Share this post


Link to post
Share on other sites



Hi guys i've been having a hard time figuring out how to convert from Hexadecimal to Decimal

my code is this

ConsoleWrite(Hex(2684354573)&@CRLF)
ConsoleWrite(Dec('A000000D')&@CRLF)

this program Should Write:

A000000D

2684354573

but the result is different:

A000000D

-1610612723

why is it that when i convert from Hex to decimal is so different that when i convert from hex to Decimal?

If Someone could help me out i would appreciate it

Thanx in advance

The help tells you why. Look up Dec and read what it says about the range of numbers allowed. So if you applied some test to the number you coul split it up like this

ConsoleWrite(Hex(2684354573)&@CRLF)
ConsoleWrite(Dec("6000000D") + Dec("40000000") &@CRLF)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

From the help file for Dec():

Remarks

The function only works with numbers that fit in a 32 bit signed integer (-2147483648 to 2147483647)

You seem to be just a little past that limit ;)

Edit: martin beat me to it

Edited by james3mg

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

From the help file for Dec():

You seem to be just a little past that limit :evil:

Edit: martin beat me to it

OK, ha ha ha, i didn't look at the 32 bits limit, Sorry Martin and James for that, and Tanx for the super quick answer

Best Regards ;)

Edited by bienmexicano

i love to draw so Go here!!!!!!!

Share this post


Link to post
Share on other sites

An example of Hex2Dec() and Dec2Hex() for big numbers.

ConsoleWrite("0x" & Hex(2684354573) & @CRLF)
ConsoleWrite(Hex2Dec('0xA000000D') & @CRLF & @CRLF)

ConsoleWrite(Hex(10995116334608) & @TAB & "0x" & Dec2Hex(10995116334608) & @CRLF)
ConsoleWrite(Hex2Dec('0xA000000DE10') & @CRLF & @CRLF)

Func Dec2Hex($iN)
    Local $ihex = ""
    Do
        $ihex = Hex(Mod($iN, 16), 1) & $ihex
        $iN = Floor($iN / 16)
        ;ConsoleWrite($iN & " " & $ihex & @CRLF)
    Until $iN = 0
    Return $ihex
EndFunc ;==>Dec2Hex


Func Hex2Dec($iN)
    Local $aN, $ihex = 0
    $aN = StringSplit(StringTrimLeft($iN, 2), "", 1)
    For $x = 1 To UBound($aN) - 1
        $ihex += Dec($aN[$x]) * (16 ^ (UBound($aN) - 1 - $x))
    Next
    Return $ihex
EndFunc ;==>Hex2Dec

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

An example of Hex2Dec() and Dec2Hex() for big numbers.

ConsoleWrite("0x" & Hex(2684354573) & @CRLF)
ConsoleWrite(Hex2Dec('0xA000000D') & @CRLF & @CRLF)

ConsoleWrite(Hex(10995116334608) & @TAB & "0x" & Dec2Hex(10995116334608) & @CRLF)
ConsoleWrite(Hex2Dec('0xA000000DE10') & @CRLF & @CRLF)

Func Dec2Hex($iN)
    Local $ihex = ""
    Do
        $ihex = Hex(Mod($iN, 16), 1) & $ihex
        $iN = Floor($iN / 16)
        ;ConsoleWrite($iN & " " & $ihex & @CRLF)
    Until $iN = 0
    Return $ihex
EndFunc ;==>Dec2Hex


Func Hex2Dec($iN)
    Local $aN, $ihex = 0
    $aN = StringSplit(StringTrimLeft($iN, 2), "", 1)
    For $x = 1 To UBound($aN) - 1
        $ihex += Dec($aN[$x]) * (16 ^ (UBound($aN) - 1 - $x))
    Next
    Return $ihex
EndFunc ;==>Hex2Dec

awesome!, thanks i think i found what i need it ;)

i love to draw so Go here!!!!!!!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

after the fact I know, but I wanted to throw this old UDF I made out there:

http://www.autoitscript.com/forum/index.php?showtopic=81189

It allows conversion from any positive base less than 63 to any other positive base less than 63, as long as the numbers you're dealing with don't output strings longer than AutoIt can handle (32767 characters, I believe). Bit length doesn't matter, since it outputs strings representing numbers rather than actual digital numbers.

Edited by james3mg

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

lol, there you go. Thanks for the correction.

And glad you like it ;)

Edited by james3mg

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

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