# Help converting Octal to Hex....easily

## Recommended Posts

Hi, I just started using this fantastic app today. I'm planning on using it in my carPC to automate a few tedious processes that would otherwise cause me to crash my car. I'm working on a script that requires me to convert an octal into its hexadecimal equivalent and I was hoping there would be a built-in function available that would do the hard work for me. I have my script completed barring this one, small problem. There doesn't seem to be a oct() function mentioned anywhere. I know I could spend a half an hour an code a function that will do this for me but I'm wondering ( hoping ) that some AutoIT guru has done this already and would be willing to share the knowledge. Thanks!!

##### Share on other sites

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.

##### Share on other sites

Hi, I just started using this fantastic app today. I'm planning on using it in my carPC to automate a few tedious processes that would otherwise cause me to crash my car. I'm working on a script that requires me to convert an octal into its hexadecimal equivalent and I was hoping there would be a built-in function available that would do the hard work for me. I have my script completed barring this one, small problem. There doesn't seem to be a oct() function mentioned anywhere. I know I could spend a half an hour an code a function that will do this for me but I'm wondering ( hoping ) that some AutoIT guru has done this already and would be willing to share the knowledge. Thanks!!

And yet another choice for your consideration.

```\$iDec = 17

\$iOct = StringFormat("%o", \$iDec); <== Conversion Dec 2 Oct
\$iOct2Hex = Hex(Oct2Dec(\$iOct), 6) ; <== Conversion Oct 2 Hex

MsgBox(0, "Decimal2Oct", "Decimal       " & "= " & \$iDec & @CRLF & _
"Hexidecimal " & "= " & "0x" & Hex(\$iDec, 6) & @CRLF & _
"Octal           " & "= " & \$iOct & @CRLF & _
"Oct2Hex     " & "= " & "0x" & \$iOct2Hex)
;
Func Oct2Dec(\$iN)
Local \$aN, \$iOct = 0
\$aN = StringSplit(\$iN, "", 1)
For \$x = 1 To UBound(\$aN) - 1
\$iOct += \$aN[\$x] * (8 ^ (UBound(\$aN) - 1 - \$x))
Next
Return \$iOct
EndFunc   ;==>Oct2Dec```

Welcome to the forums.

##### Share on other sites

Thanks for all the help, I trawled through those suggestions and managed to get it going last night. Although, that method last posted seems to be a lot "cleaner" than what I ended up with. Thanks

## Create an account

Register a new account