Sign in to follow this  
Followers 0
Diaa

[Help] Hex to int32

4 posts in this topic

Hello

I need help to convert Hex data to int32 in autoit

for example I have this data in Hex

BA D0 01 00

and I want to convert it to int32 which will be

118970

thank you

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You have me confused, hexadecimal is a base 16 number system, and Int32 is a format for storing a numeric variable in memory.

I can't think of any sort of conversion that turns BAD00100 (or 0100BADO) into 118970.

Edited by Spiff59

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Right, wouldn't 118970 be 0001D0BA?

Edit: It's okay, I'm dyslexic too :)

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Right, wouldn't 118970 be 0001D0BA?

Edit: It's okay, I'm dyslexic too :)

You're right! I didn't get "endian" enough with it. Flopped words, but not bytes, then words.

To the OP: There are a bunch of base conversion routines around easily found by doing a forum search.

Here's one:

$result = _BaseConvert("1D0BA", 16, 10)
MsgBox(0,"",$result)

;===================================================================================================================================
Func _BaseConvert($sIn, $iBaseIn, $iBaseOut)
    Local $sOut = 0
    If $iBaseIn <> 10 Then ; iBaseIn to decimal
        $aIn = StringSplit($sIn, "")
        For $x = 1 to $aIn[0]
            $asc = Asc($aIn[$x])
            $iDec = $asc - (48 + ($asc > 57) * 7) ; [0-9][A-Z]
            $sOut += $iDec * ($iBaseIn ^ ($aIn[0] - $x))
        Next
        $sIn = $sOut
    EndIf

    If $iBaseOut <> 10 Then ; decimal to iBaseOut
        $sOut = ""
        While $sIn >= 1
         $x = Mod($sIn, $iBaseOut)
            $sOut = Chr($x + 48 + ($x > 9) * 7) & $sOut ; [0-9][A-Z]
            $sIn = ($sIn - $x) / $iBaseOut
        WEnd
    EndIf
    Return $sOut
EndFunc

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