Tools Links Login

Simple Decimal To Binary Converter

This simple code will convert the Long Integers to it's binary Equivalent...

Original Author: Raj A

Inputs

Long Integers ( positive ) 1 - 999999999

Assumptions

This program is not capable of accepting negative numbers or numbers which are more than 999999999

Returns

if the range is met then this will return the Binary equivalent...
if the input is either non-numeric or not in range ( 1 - 999999999 ) then
it won't continue.....

Code

Option Explicit
'********************************************'
'***This Function is to just to Return the***'
'***Binary Equivalent for Any long integer***'
'********************************************'
Private Sub Command1_Click()
  
  Dim str1 As String
  
  On Error GoTo a:
  
  str1 = cBin(CLng(Text1.Text))
  
  MsgBox str1
  
  Exit Sub
a:
End Sub
Public Function cBin(a As Long) As String
  
  Dim bal As Long
  Dim str1 As String
  
  bal = a
  
    Do Until a <= 0
      bal = a Mod 2
      If bal = 0 Then
        a = a / 2
      Else
        a = (a - 1) / 2
      End If
      str1 = str1 & CStr(bal)
    Loop
    
    cBin = StrReverse(str1)
    
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 109 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.