bienmexicano Posted January 7, 2010 Share Posted January 7, 2010 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!!!!!!! Link to comment Share on other sites More sharing options...
martin Posted January 7, 2010 Share Posted January 7, 2010 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. Link to comment Share on other sites More sharing options...
james3mg Posted January 7, 2010 Share Posted January 7, 2010 (edited) From the help file for Dec():RemarksThe 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 January 7, 2010 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 Link to comment Share on other sites More sharing options...
bienmexicano Posted January 7, 2010 Author Share Posted January 7, 2010 (edited) From the help file for Dec():You seem to be just a little past that limit Edit: martin beat me to itOK, ha ha ha, i didn't look at the 32 bits limit, Sorry Martin and James for that, and Tanx for the super quick answerBest Regards Edited January 7, 2010 by bienmexicano i love to draw so Go here!!!!!!! Link to comment Share on other sites More sharing options...
Malkey Posted January 8, 2010 Share Posted January 8, 2010 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 Link to comment Share on other sites More sharing options...
MvGulik Posted January 8, 2010 Share Posted January 8, 2010 (edited) whatever Edited February 7, 2011 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 ... Link to comment Share on other sites More sharing options...
bienmexicano Posted January 8, 2010 Author Share Posted January 8, 2010 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!!!!!!! Link to comment Share on other sites More sharing options...
james3mg Posted January 8, 2010 Share Posted January 8, 2010 (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 January 8, 2010 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 Link to comment Share on other sites More sharing options...
MvGulik Posted January 8, 2010 Share Posted January 8, 2010 (edited) whatever Edited February 7, 2011 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 ... Link to comment Share on other sites More sharing options...
james3mg Posted January 8, 2010 Share Posted January 8, 2010 (edited) lol, there you go. Thanks for the correction. And glad you like it Edited January 8, 2010 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 Link to comment Share on other sites More sharing options...
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