by Raj A (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating:
(3 Votes)
This simple code will convert the Long Integers to it's binary Equivalent...
Inputs
Long Integers ( positive ) 1 - 999999999
Assumes
This program is not capable of accepting negative numbers or numbers which are more than 999999999
Code 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.....
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