# How to onvert binary to hex?

## Recommended Posts

Hello,everyone!

Here ,i want to convert binary ("01100001") to hex ("a").

Which function can do this?

Thanks!

I was try this

\$z1 = BinaryToString("01100001")

As result, \$z1 contained "01100001" instead of the expected result "a".

Edited by Xwolf

##### Share on other sites

try this:

#include <string.au3>

\$String = "01100001"

\$result = Hex(\$String , 4)

MsgBox(0, "Hex", "Original String: " & \$String & @LF & " Hex: " & \$result)

please if this works or any other solution works...say so and

tag your original post as [sOLVED] or [RESOLVED]

Al

Edited by alram

##### Share on other sites

I wrote this to convert from hex to binary, the inverse should work for what you are looking for.

```Func Convert_to_binary(\$IDim)

Select
Case \$IDim = "F"
Return "1111"
Case \$IDim = "E"
Return "1110"
Case \$IDim = "D"
Return "1101"
Case \$IDim = "C"
Return "1100"
Case \$IDim = "B"
Return "1011"
Case \$IDim = "A"
Return "1010"
Case \$IDim = "9"
Return "1001"
Case \$IDim = "8"
Return "1000"
Case \$IDim = "7"
Return "0111"
Case \$IDim = "6"
Return "0110"
Case \$IDim = "5"
Return "0101"
Case \$IDim = "4"
Return "0100"
Case \$IDim = "3"
Return "0011"
Case \$IDim = "2"
Return "0010"
Case \$IDim = "1"
Return "0001"
Case \$IDim = "0"
Return "0000"
EndSelect
EndFunc  ;==>Convert_to_binary```

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

##### Share on other sites

```Func BinToHex(\$Bin, \$Lenght = 2)
Local \$b, \$c, \$d, \$e
\$b = StringLen(\$Bin)
For \$i = 1 To \$b
\$c = StringMid(\$Bin, \$i, 1)
\$d = \$b - \$i
\$e = \$c * (2 ^ \$d)
\$Result = \$Result + \$e
Next
\$Result = Hex(\$Result, \$Lenght)
Return \$Result
EndFunc  ;==>ToText```

example:

`MsgBox(0,'', BinToHex('01100001'))`

##### Share on other sites

thanks ombra that works with one modification

looks like you miss to declare \$Result:

Local \$b, \$c, \$d, \$e, \$Result

Please if this works or any other solution works...say so and

tag your original post as [sOLVED] or [RESOLVED]

Al

Edited by alram

## Create an account

Register a new account