Jump to content

How to onvert binary to hex?


Xwolf
 Share

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
Link to comment
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
Link to comment
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.

Link to comment
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'))
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...