- Home
·
- Math/Dates
·
- Binary Module 1.0. This module includes functions for converting decimal numbers to binary and vice
Binary Module 1.0. This module includes functions for converting decimal numbers to binary and vice
Binary Module 1.0. This module includes functions for converting decimal numbers to binary and vice versa.
API Declarations
'by Buttress Root Software
'
'Programmed by Jonathan Liu
'Copyright ©1999-2371 Buttress Root Software. All rights reserved.
Option Explicit
Rate Binary Module 1.0. This module includes functions for converting decimal numbers to binary and vice
(2(2 Vote))
Function DecToBin(ByVal dblDecimal As Double) As String
Dim dblBuffer As Double
Dim i As Single
If dblDecimal = 0 Then Exit Function
dblBuffer = dblDecimal
Do
If dblBuffer / 2 <> Round(dblBuffer / 2) Then
DecToBin = "1" & DecToBin
dblBuffer = dblBuffer \ 2
Else
DecToBin = "0" & DecToBin
dblBuffer = dblBuffer / 2
End If
Loop Until dblBuffer < 1
End Function
Function BinToDec(ByVal strBinary As String) As Double
Dim dblBuffer As Double
Dim i As Single
If strBinary = "" Then Exit Function
For i = Len(strBinary) To 1 Step -1
dblBuffer = dblBuffer + Val(Mid(strBinary, i, 1)) * 2 ^ (Len(strBinary) - i)
Next i
BinToDec = dblBuffer
End Function
Binary Module 1.0. This module includes functions for converting decimal numbers to binary and vice Comments
No comments yet — be the first to post one!
Post a Comment