Results 1 to 7 of 7

Thread: Hex To Bin

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    9

    Hex To Bin

    I have a text box (txtbox1) where I want to enter a 2 character HEX number, ( ie. 3F)
    and another text box (txtbox2) where I want the conversion to bininary to appear. To execute the conversion I have a Command Button (cmd1) set to click.



    Part 2 of my goal is to invert the bininary during the conversion process as in the example below.

    example... 11001011 would appear as 11010011

    If anyone can help me with this I would appreciate it very much. I am a beginner with programming so please keep that in mind when writing answers.

    Thank You,
    George

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Hex To Bin

    This has been asked several times already. Please do a search.

  3. #3
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Hex To Bin

    to simply do it, you can append the &H in front of it.
    msgbox val("&H" + textbox1.text)
    converting it to a number is the first step. You will then need to convert it to binary from that number. This is more difficult. Ready-made functions though are already in the code bank.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  4. #4
    Hyperactive Member jp26198926's Avatar
    Join Date
    Sep 2008
    Location
    General Santos City, Philippines
    Posts
    310

    Re: Hex To Bin

    try this.

    Code:
    Public Function HexToBinary(H as String) As String
    Dim B as String
    Dim i as Integer
    
    For i = 1 To Len(H)
    Select Case Lcase(Mid(H, i, 1))
     Case "0" 
         B = B + "0000"
     Case "1" 
        B = B + "0001"
     ............
    
     Case "e" 
        B = B + "1110"
     Case "f" 
        B = B + "1111"
    End Select
    Next i
    
    HexToBinary = B
    End Function

    Private Sub cmd1_Click()

    txtbox1.text = HextoBinary (txtbox2.text)

    End sub
    Last edited by jp26198926; Nov 25th, 2008 at 09:49 PM.
    "More Heads are Better than One"

  5. #5
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Hex To Bin

    Quote Originally Posted by jp26198926
    try this.

    Code:
    Public Function HexToBinary(H as String) As String
    Dim B as String
    Dim i as Integer
    
    For i = 1 To Len(H)
    Select Case Lcase(Mid(H, i, 1))
     Case "0" 
         B = B + "0000"
     Case "1" 
        B = B + "0001"
     ............
    
     Case "e" 
        B = B + "1110"
     Case "f" 
        B = B + "1111"
    End Select
    Next i
    
    HexToBinary = B
    End Function

    Private Sub cmd1_Click()

    txtbox1.text = HextoBinary (txtbox2.text)

    End sub
    if you're going to go about it in this manner, you might as well reverse the order of the bits in this code.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  6. #6
    Hyperactive Member jp26198926's Avatar
    Join Date
    Sep 2008
    Location
    General Santos City, Philippines
    Posts
    310

    Re: Hex To Bin

    Private Sub cmd1_Click()
    txtbox1.text = HextoBinary (txtbox2.text)
    txtbox1.text= StrReverse (txtbox1.text)
    End Sub
    "More Heads are Better than One"

  7. #7
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Hex To Bin

    i am unclear on whether or not he needs the entire string reversed, or the individual bits of each letter.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

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