Jump to content

[Help] Hex to int32


Diaa
 Share

Recommended Posts

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
Link to comment
Share on other sites

  • Moderators

Right, wouldn't 118970 be 0001D0BA?

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

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...