PDA

Click to See Complete Forum and Search --> : Translate Decimal to Binary?


rino_2
Jan 15th, 2000, 04:55 AM
Hi,

I have asked this question before but I can't remember the answer (sorry). I have a text box called txtDecimal and would like to translate the number in there into Binary and then display it in a label called lblBinary. Could somebody please help?

Thanks

r0ach
Jan 15th, 2000, 05:03 AM
This code was taken from this site:

Public Sub DecBin(Adecimal, jbin As String)
'Convert integer value to an equivalent string of binary digits
jbin = ""
h = Hex(Adecimal) 'convert from integer to hexadecimal
For i = 1 To Len(h)
digit = InStr("0123456789ABCDEF", Mid(h, i, 1)) - 1
j = 8
k = 4
Do 'convert from hexadecimal to binary
jbin = jbin + Right(Str((digit ^ j) Mod 2), 1)
j = j - (j ^ 2)
k = k - 1
If k = 0 Then Exit Do
Loop While j
Next i
End Sub


------------------
r0ach(tm)