John_C
asked on
Convert a hex number to binary
What is the function to convert a hex number to binary in VB? Thanks.
val() will return the binary format, but you need to pass the hex number a special way. I'll have to look it up and get back to you.
ok .. I guess it's just Val("&H80000F&") Just pass the hex number in quotes . . make sure there's a & on either end
Private Sub Command1_Click()
Dim lngX As Long
Dim lngY As Long
Dim strBinary As String
lngX = &HAAAAAAAA
lngY = 1
On Error Resume Next
strBinary = ""
Do While Err.Number = 0
If lngX And lngY Then
strBinary = "1" & strBinary
Else
strBinary = "0" & strBinary
End If
lngY = lngY + lngY
Loop
If lngX And &H80000000 Then
strBinary = "1" & strBinary
Else
strBinary = "0" & strBinary
End If
MsgBox strBinary
End Sub
Dim lngX As Long
Dim lngY As Long
Dim strBinary As String
lngX = &HAAAAAAAA
lngY = 1
On Error Resume Next
strBinary = ""
Do While Err.Number = 0
If lngX And lngY Then
strBinary = "1" & strBinary
Else
strBinary = "0" & strBinary
End If
lngY = lngY + lngY
Loop
If lngX And &H80000000 Then
strBinary = "1" & strBinary
Else
strBinary = "0" & strBinary
End If
MsgBox strBinary
End Sub
(Change the value of lngX to see different results)
That's fine and dandy for doing a few but what is you are talking reasonable size files ie 100k +
I takes foreverm anyone got any quicker solutions (I know this isn't my question but hey)
I takes foreverm anyone got any quicker solutions (I know this isn't my question but hey)
ASKER
Thanks everyone.
I tried Val(), but seems like it only returns in decimal format, even if I pass the number using BeedleGuis' format. May be different version? I'm using VB6.
There is no build-in function in VB?
I tried Val(), but seems like it only returns in decimal format, even if I pass the number using BeedleGuis' format. May be different version? I'm using VB6.
There is no build-in function in VB?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.
Yes I'm aware that computer stores everything in binary format.
If the function doesn't exist I'll use a function to do it.
Yes I'm aware that computer stores everything in binary format.
If the function doesn't exist I'll use a function to do it.