by sherif rofael (15 Submissions)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 23rd July 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Convert any real number from base 10 to base 2, i.e. (decimal with decimal point to its binary equivalent) for ex: 152.75------>10011000.11
API Declarations
' http://sherif1.netfirms.com/vbcode/binary.zip
' how to use:
' download the whole project from the link above or:
' use the functions in the code (dec , bin , u)
' **function "u" calculates the numbers of bits the binary # will be.
' **function "bin" converts the integer part of the # to its binary
' equivalent.
' **function "dec" converts the fraction part of the decimal #
' to its binary equivalent.
' by : sherif rofael.
' mailto : [email protected]
' website:
' http://sherif1.netfirms.com
' http://vbsherif.members.easyspace.com (to download the programs)
Dim s As String, i As Integer
uu = u(x)
'Print uu
For i = 0 To uu
s = (n Mod 2) & s
t = n / 2
n = Int(t)
Next
Bin = s
End Function
Private Sub a_Change()
a = a
End Sub
Private Sub Combo1_Change()
'If Combo1 <> "# of bits" Then a = Combo1
End Sub
Private Sub Command1_Click()
'Print a, Combo1
'If Combo1 <> "# of bits" Then a = Combo1
Dim mm As Double
mm = Int(x)
e = x - mm
Y1 = Bin(mm)
Y2 = dec(e, a)
Y3 = StrReverse(Y2)
y = Y1 & "." & Y3
'y = length(x)
End Sub
Function u(d)
'v1 = Int(Log(x) / Log(2))
'v2 = Log(x) / Log(2)
'If v1 = v2 Then u = v1
'If v1 <> v2 Then u = v1
u = Int(Log(x) / Log(2))
End Function
Function dec(q, a)
For i = 1 To a
w = q * 2
If Int(w) = 1 Then
dec = 1 & dec
q = w - 1
End If
If Int(w) = 0 Then
dec = 0 & dec
q = w
End If
'Print dec
If q = 0 Then
'Print dec
Exit For
End If
Next i
'Print dec
End Function
Private Sub Form_Load()
a = 8
Option1.Enabled = False
Option2.Enabled = False
Option3.Enabled = False
Option7.Enabled = False
Option8.Enabled = False
Option9.Enabled = False
Option10.Enabled = False
Option11.Enabled = False
Option6.Enabled = False
End Sub
Private Sub Option1_Click()
a = 8
End Sub
Private Sub Option10_Click()
a = 24
End Sub
Private Sub Option11_Click()
a = 30
End Sub
Private Sub Option2_Click()
a = 16
End Sub
Private Sub Option3_Click()
a = 36
End Sub
Private Sub Option4_Click()
Option1.Enabled = False
Option2.Enabled = False
Option3.Enabled = False
Option7.Enabled = False
Option8.Enabled = False
Option9.Enabled = False
Option10.Enabled = False
Option11.Enabled = False
Option6.Enabled = False
'Option5.Enabled = False
Option4.Enabled = True
'Combo1.Enabled = False
a.Enabled = True
End Sub
Private Sub Option5_Click()
'Option4.Enabled = False
a.Enabled = False
Option1.Enabled = True
Option2.Enabled = True
Option3.Enabled = True
Option7.Enabled = True
Option8.Enabled = True
Option9.Enabled = True
Option10.Enabled = True
Option11.Enabled = True
Option6.Enabled = True
Option5.Enabled = True
'Combo1.Enabled = True
End Sub
Private Sub Option6_Click()
a = 4
End Sub
Private Sub Option7_Click()
a = 6
End Sub
Private Sub Option8_Click()
a = 12
End Sub
Private Sub Option9_Click()
a = 20
End Sub
No comments have been posted about Convert any real number from base 10 to base 2, i.e. (decimal with decimal point to its binary equi. Why not be the first to post a comment about Convert any real number from base 10 to base 2, i.e. (decimal with decimal point to its binary equi.