Xwolf Posted November 21, 2008 Posted November 21, 2008 (edited) 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 November 21, 2008 by Xwolf
theAutoitSpammer Posted November 21, 2008 Posted November 21, 2008 (edited) 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 November 21, 2008 by alram
Kerros Posted November 21, 2008 Posted November 21, 2008 I wrote this to convert from hex to binary, the inverse should work for what you are looking for. expandcollapse popupFunc 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.
oMBRa Posted November 21, 2008 Posted November 21, 2008 I quickly made this function: 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'))
theAutoitSpammer Posted November 21, 2008 Posted November 21, 2008 (edited) 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 November 21, 2008 by alram
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now