Results 1 to 6 of 6

Thread: Convert Hex to Bin ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    430

    Convert Hex to Bin ?

    Isn't there a function that converts HEX to BIN?

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    Hex to bin is really easy to do just remember this

    0 = 0000
    1 = 0001
    2 = 0010
    3 = 0011
    4 = 0100
    5 = 0101
    6 = 0110
    7 = 0111
    8 = 1000
    9 = 1001
    A = 1010
    B = 1011
    C = 1100
    D = 1101
    E = 1110
    F = 1111

    Hope this helps,

  3. #3
    Addicted Member Geoff Gunson's Avatar
    Join Date
    Jun 1999
    Posts
    241
    This function will convert any decimal number 0 to 255 to its binary equivilant.

    Code:
    Public Function convertBinary(Number As Byte) As String
    Dim I As Byte, bStr As String
    
        
        For I = 0 To 7
            If (Number And (2 ^ I)) = (2 ^ I) Then
                bStr = bStr & "1"
            Else
                bStr = bStr & "0"
            End If
        Next I
        
        convertBinary = StrReverse(bStr)
        
    End Function
    HTH

    G

  4. #4
    Addicted Member Geoff Gunson's Avatar
    Join Date
    Jun 1999
    Posts
    241
    Or this one (with out the strReverse function DOH)

    Code:
    Public Function convertBinary(Number As Byte) As String Dim I As Byte For I = 0 To 7 If (Number And (2 ^ I)) = (2 ^ I) Then convertBinary = "1" & convertBinary Else convertBinary = "0" & convertBinary End If Next I End Function
    HTH

    G

  5. #5
    Megatron
    Guest
    This will convert Hex to Bin.
    VB Code:
    1. Public Function Hex2Bin(ByVal dwHex As String) As String
    2.     dwHex = CStr(dwHex)
    3.     Dim sTemp As String
    4.     For I = 1 To Len(dwHex)
    5.         sTemp = Mid(dwHex, I, 1)
    6.         Select Case sTemp
    7.             Case "0": Hex2Bin = Hex2Bin & "0000"
    8.             Case "1": Hex2Bin = Hex2Bin & "0001"
    9.             Case "2": Hex2Bin = Hex2Bin & "0010"
    10.             Case "3": Hex2Bin = Hex2Bin & "0011"
    11.             Case "4": Hex2Bin = Hex2Bin & "0100"
    12.             Case "5": Hex2Bin = Hex2Bin & "0101"
    13.             Case "6": Hex2Bin = Hex2Bin & "0110"
    14.             Case "7": Hex2Bin = Hex2Bin & "0111"
    15.             Case "8": Hex2Bin = Hex2Bin & "1000"
    16.             Case "9": Hex2Bin = Hex2Bin & "1001"
    17.             Case "A": Hex2Bin = Hex2Bin & "1010"
    18.             Case "B": Hex2Bin = Hex2Bin & "1011"
    19.             Case "C": Hex2Bin = Hex2Bin & "1100"
    20.             Case "D": Hex2Bin = Hex2Bin & "1101"
    21.             Case "E": Hex2Bin = Hex2Bin & "1110"
    22.             Case "F": Hex2Bin = Hex2Bin & "1111"
    23.         End Select
    24.     Next I
    25. End Function

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    430
    Thanks everybody..............

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width