|
-
Nov 25th, 2008, 08:23 PM
#1
Thread Starter
New Member
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
-
Nov 25th, 2008, 09:26 PM
#2
Re: Hex To Bin
This has been asked several times already. Please do a search.
-
Nov 25th, 2008, 09:34 PM
#3
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.
-
Nov 25th, 2008, 09:40 PM
#4
Hyperactive Member
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"
-
Nov 27th, 2008, 12:23 PM
#5
Re: Hex To Bin
 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.
-
Nov 27th, 2008, 12:51 PM
#6
-
Nov 28th, 2008, 09:19 AM
#7
Re: Hex To Bin
i am unclear on whether or not he needs the entire string reversed, or the individual bits of each letter.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|