Jump to content

Quick hex question


Gar
 Share

Recommended Posts

I can't really figure out how to do this in AutoIT, any help would be appreciated. How do I detect a certain digit in a hex number, like the 5 in 0x0050, and how do I then change it to a 3, like 0x0030?

Pseudocode:

Func ThirdDigitTo3($hex)

if {third digit of $hex) = 5 Then

...{change third digit of $hex to 3}

endif

Endfunc

Thanks!

Link to comment
Share on other sites

$a = 0x0050
$b = String(Hex($a, 4))

$split = StringSplit($b, "")

If $split[3] = 5 Then $split[3] = 3
$new = "0x"&$split[1]&$split[2]&$split[3]&$split[4]
$new_nbr = Hex($new, 4)

MsgBox(0, "new number", $new_nbr)

Can be refined or made simpler but I don't have much time now ...

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

I can't really figure out how to do this in AutoIT, any help would be appreciated. How do I detect a certain digit in a hex number, like the 5 in 0x0050, and how do I then change it to a 3, like 0x0030?

Pseudocode:

Func ThirdDigitTo3($hex)

if {third digit of $hex) = 5 Then

...{change third digit of $hex to 3}

endif

Endfunc

Thanks!

Try this

$hex = 0x40550
MsgBox(0, "", SecondDigitTo3($hex))

Func SecondDigitTo3($hex)
    If BitAND($hex, 0x000000F0) = 0x00000050 Then
        $hex = BitOR(BitAND($hex, 0xFFFFFF0F), 0x00000030)
    EndIf
    Return Hex($hex)
EndFunc   ;==>ThirdDigitTo3
Link to comment
Share on other sites

When the hex string are passed to a function it automatically convert to a decimal value :P

??

When a hex value is passed to a function that value is passed. Whether it is decimal or hex is a question of how you want to deal with it in the function, isn't it?

When a string is pased to a function that string is passed.

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

??

When a hex value is passed to a function that value is passed. Whether it is decimal or hex is a question of how you want to deal with it in the function, isn't it?

When a string is pased to a function that string is passed.

I know, see the example:

MsgBox(0, "Decimal", Dec("0000FFFF")) ;Show a decimal representation

_HexShow(0x0000FFFF) ;Pass to function as Hex
_HexShow("0000FFFF") ;Pass to function as string

Func _HexShow($sParam)
    MsgBox(0, "Hex?", $sParam)
EndFunc

what will you say? :P

Link to comment
Share on other sites

It's not so much that 0x1 is converted to decimal when it's passed, it's just that it's a different way of specifying a number. Just the same as 1e0 is.

If 1 = 0x1 Then ConsoleWrite(1)
If 1 = 1e0 Then ConsoleWrite(2)
If 0x1 = 1e0 Then ConsoleWrite(3)
If 10 = 0xA Then ConsoleWrite(4)
If 10 = 1e1 Then ConsoleWrite(5)
If 0xA = 1e1 Then ConsoleWrite(6)

No functions to do converting there. :P

*Edit: But I'm getting off topic here, so I'll stop now.

Edited by RobSaunders
Link to comment
Share on other sites

It's not so much that 0x1 is converted to decimal when it's passed, it's just that it's a different way of specifying a number. Just the same as 1e0 is.

If 1 = 0x1 Then ConsoleWrite(1)
If 1 = 1e0 Then ConsoleWrite(2)
If 0x1 = 1e0 Then ConsoleWrite(3)
If 10 = 0xA Then ConsoleWrite(4)
If 10 = 1e1 Then ConsoleWrite(5)
If 0xA = 1e1 Then ConsoleWrite(6)

No functions to do converting there. :P

*Edit: But I'm getting off topic here, so I'll stop now.

i think what he meant is :

If 1 = 0x1 Then ConsoleWrite(0x1)
If 1 = 1e0 Then ConsoleWrite(0x2
If 0x1 = 1e0 Then ConsoleWrite(0x3)
If 10 = 0xA Then ConsoleWrite(0x4)
f 10 = 1e1 Then ConsoleWrite(0x5)
If 0xA = 1e1 Then ConsoleWrite(0x6)
Edited by TheMadman

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

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