Jump to content

Quick question about Dec()


rbhkamal
 Share

Recommended Posts

From the Help file:

Remarks

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

How can I convert the Dword value "80000000" to decimal value?

When I use Dec() I get -2147483648 but that is incorrect; it should be 2147483648.

Is it because that value is too large?

Regards,

RK

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Link to comment
Share on other sites

Correction:

Using the calculator hex 800000 to decimal is 34359738368.

But strange that RegRead also returns the wrong value.... :whistle:

RK

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Link to comment
Share on other sites

Hmm, I wrote a quick script to convert hex to dec (taken from some old vbs I had).. and it gives me 2147483648.

$sHex = InputBox("Hex to Decimal","Enter Hex Here", "80000000")
$iDecimal = HexToDec($sHex)
MsgBox(0, "Decimal", $iDecimal)

Func HexToDec($sHex)
Local $iHexLength, $iHexLength2, $iDecimal, $iDecVal, $iResult
$iHexLength = StringLen($sHex)
$iHexLength2 = $iHexLength
For $i = 1 to $iHexLength
    $iDecVal = StringLeft(StringMid($sHex,$i,1),$i)
    If StringInStr(StringUpper($iDecVal), "A") Then $iDecVal = 10
    If StringInStr(StringUpper($iDecVal), "B") Then $iDecVal = 11
    If StringInStr(StringUpper($iDecVal), "C") Then $iDecVal = 12
    If StringInStr(StringUpper($iDecVal), "D") Then $iDecVal = 13
    If StringInStr(StringUpper($iDecVal), "E") Then $iDecVal = 14
    If StringInStr(StringUpper($iDecVal), "F") Then $iDecVal = 15
    If $iHexLength2 >= 3 Then
        $iResult = $iDecVal*16^($iHexLength - $i)
        $iHexLength2 = $iHexLength2 - 1
    ElseIf $iHexLength2 = 2 Then
        $iResult = $iDecVal * 16
        $iHexLength2 = $iHexLength2 - 1
    ElseIf $iHexLength2 = 1 Then
        $iResult = $iDecVal
    EndIf
    $iDecimal = $iDecimal + $iResult
Next
Return($iDecimal)
EndFunc
Edited by Simucal
AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

MsgBox(4096,"",0x80000000)

hmmm.. I dunno.

Lar.

I'm confused... can you explain a little more.

I'm trying to compare a registry value (dword:80000000) with a string that contains a Dword "8000000", but when I use RegRead() I get 2147483648 and when I convert the string using Dec() I get -2147483648.

RK

Edit: Uh...I guess Friday is the wrong day to write programs, I can't even understand what I wrote five minutes ago.....

@Simucal

Thanks for your function.

Edited by rbhkamal

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Link to comment
Share on other sites

No problem.. it could probably be slimmed down a little and a little error checking needs to be added in, but it works so far in my testing.

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

  • Moderators

$value = '2147483648';RegRead(etc...)
MsgBox(0,'', '0x' & Hex($value))oÝ÷ ØGb´Ú-jÇ¥iº+j×±(¦¹Æ¥nëH笲+`zÛ-ëêÞ²émjëh×6$value = '2147483648';RegRead(etc...)
$Hex = '0x' & Hex($value)
$Dec = Execute($Hex)
MsgBox(0,'', $Hex & @CR & $Dec)

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

$value = '2147483648';RegRead(etc...)
MsgBox(0,'', '0x' & Hex($value))oÝ÷ ØGb´Ú-jÇ¥iº+j×±(¦¹Æ¥nëH笲+`zÛ-ëêÞ²émjëh×6$value = '2147483648';RegRead(etc...)
$Hex = '0x' & Hex($value)
$Dec = Execute($Hex)
MsgBox(0,'', $Hex & @CR & $Dec)
But doesn't that give him the same negative result he was having trouble with before?
AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

  • Moderators

But doesn't that give him the same negative result he was having trouble with before?

Well, if Larry's post wasn't enough to convince anyone... you could always treat it like strings like you did in your function:
$value = '2147483648';RegRead(etc...)
$Hex = '0x' & Hex($value)
MsgBox(0,'', _HexToDec($Hex))

Func _HexToDec($sHex)
    If StringLeft($sHex, 2) <> '0x' Then $sHex = '0x' & $sHex
    $sHex = Execute($sHex)
    If StringLeft($sHex, 1) = '-' Then Return Int(StringTrimLeft($sHex, 1))
    Return Int($sHex)
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thanks everyone :whistle:

I guess now I can safely ignore the "-" sign.... I'll just check if $value < 0 then $value *= -1.

Ragards,

RK

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

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...