Jump to content

Hex num to String (ex. 0xEAB095 to "EAB095")


circcc
 Share

Recommended Posts

  • Moderators

how can I convert hex number to string.

for example,

Hex: 0xEAB095

Stirng: "EAB095"

thanks in advance.

$sHex = "0xEABO95"
$sString = StringReplace($sHex, "0x", "")
MsgBox(0, "1", $sString)
$sString = StringRegExpReplace($sHex, "(0x)", "")
MsgBox(0, "2", $sString)
$sString = StringTrimLeft($sHex, 2)
MsgBox(0, "3", $sString)
$sString = StringRight($sHex, StringLen($sHex) - 2)
MsgBox(0, "4", $sString)
$sString = StringMid($sHex, 3)
MsgBox(0, "5", $sString)

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

$sHex = "0xEABO95"
$sString = StringReplace($sHex, "0x", "")
MsgBox(0, "1", $sString)
$sString = StringRegExpReplace($sHex, "(0x)", "")
MsgBox(0, "2", $sString)
$sString = StringTrimLeft($sHex, 2)
MsgBox(0, "3", $sString)
$sString = StringRight($sHex, StringLen($sHex) - 2)
MsgBox(0, "4", $sString)
$sString = StringMid($sHex, 3)
MsgBox(0, "5", $sString)
thanks but, 0xEABO95 is number as I said.
Link to comment
Share on other sites

  • Moderators

thanks but, 0xEABO95 is number as I said.

You make no sense.

You're example shows you have the hex number and want a string... I've provided that.

If you have a hex string that you want to convert to a decimal, you could try:

$sString = "EAB095"
MsgBox(0, "", Dec($sString))oÝ÷ Øò¢èZ½æyȦjV§w§¶Ú¢{ޮح¶^Å«­¢+ØÀÌØí¹ôÄÔÌàÀØÈä)5Í    ½à À°ÅÕ½ÐìÅÕ½Ðì°!à ÀÌØí¹°Ø¤¤

If that does not answer your question, I'd need a bit more understanding of what you are trying to accomplish.

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

You make no sense.

You're example shows you have the hex number and want a string... I've provided that.

If you have a hex string that you want to convert to a decimal, you could try:

$sString = "EAB095"
MsgBox(0, "", Dec($sString))oÝ÷ Øò¢èZ½æyȦjV§w§¶Ú¢{ޮح¶^Å«­¢+ØÀÌØí¹ôÄÔÌàÀØÈä)5Í    ½à À°ÅÕ½ÐìÅÕ½Ðì°!à ÀÌØí¹°Ø¤¤

If that does not answer your question, I'd need a bit more understanding of what you are trying to accomplish.

$sHex = "0xEAB095" ;for string

$sHex = 0xEAB095 ;for number

am I wrong?

Edited by circcc
Link to comment
Share on other sites

$sHex = "0xEABO95"

autoit doesnot have a Variable in number or string. all Variables in autoit is variant

And will become a string when you use &

and will become a number when + - * / is use

Edited by athiwatc
Link to comment
Share on other sites

  • Moderators

$sHex = "0xEAB095" ;for string

$sHex = 0xEAB095 ;for number

am I wrong?

If you are asking if $sHex = 0xEAB095 is a "number" the answer is no, it's a hex lol (just poking)... AutoIt converts it to a decimal when you view it.

There are two ways to convert your "hex" string to a decimal.

1. $nHex = Dec(StringReplace("0xEAB095", "0x", ""))

2. $nHex = Execute("0xEAB095")

If you want to check if 0xEAB095 is equal to a decimal, you could do something like:

;If 0xEAB095 = 15380629 Then works here as well, but I have a sneaky suspicion that you are playing with PixelGetColor, so see the example below
If (0xEAB095 == 15380629) Then MsgBox(64, "Info", "0xEAB095 equals 15380629")

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

If you are asking if $sHex = 0xEAB095 is a "number" the answer is no, it's a hex lol (just poking)...

you're wrong. it is numbers

there is no hex datatype.(datatype: Numbers/Strings/Booleans/Binary)

$sHex = 0xEAB095 is a number

$sHex = "0xEAB095" is a binary

here is manual.

"

Numbers

Numbers can be standard decimal numbers like 2, 4.566, and -7.

Scientific notation is also supported; therefore, you could write 1.5e3 instead of 1500.

Integers (whole numbers) can also be represented in hexadecimal notation) by preceding the integer with 0x as in 0x409 or 0x4fff (when using hex notation only 32-bit numbers are valid).

"

I solve the problem with manual. the answer is binary datatype. that is reason why binary datatype is exist.

regards.

Edited by circcc
Link to comment
Share on other sites

  • Moderators

you're wrong. it is numbers

there is no hex datatype.(datatype: Numbers/Strings/Booleans/Binary)

$sHex = 0xEAB095 is a number

$sHex = "0xEAB095" is a binary

here is manual.

"

Numbers

Numbers can be standard decimal numbers like 2, 4.566, and -7.

Scientific notation is also supported; therefore, you could write 1.5e3 instead of 1500.

Integers (whole numbers) can also be represented in hexadecimal notation) by preceding the integer with 0x as in 0x409 or 0x4fff (when using hex notation only 32-bit numbers are valid).

"

I solve the problem with manual. the answer is binary datatype. that is reason why binary datatype is exist.

regards.

I'm wrong? You can't explain that you're looking for a "Data Type"... you make it seem that you are looking for a way to convert... I give you an answer based on what you wrote, and you want to be a smart ass? If you note,

If you are asking if $sHex = 0xEAB095 is a "number" the answer is no, it's a hex lol (just poking)

If you read that again, I was just having a jestful moment with you...

Congratulations on finding a solution... However, simply explaining that you would like to know the data type would have gotten your question answer much faster...

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

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