Sign in to follow this  
Followers 0
Xwolf

How to onvert binary to hex?

5 posts in this topic

#1 ·  Posted (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 by Xwolf

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by alram

Share this post


Link to post
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 this post


Link to post
Share on other sites

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'))

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

thanks ombra that works with one modification

looks like you miss to declare $Result:

Local $b, $c, $d, $e, $Result :mellow:

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 this post


Link to post
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
Sign in to follow this  
Followers 0