Results 1 to 2 of 2

Thread: Translate Decimal to Binary?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    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

  2. #2
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Post

    This code was taken from this site:
    Code:
    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)

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