VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Binary Module 1.0. This module includes functions for converting decimal numbers to binary and vice

by Jonathan Liu (9 Submissions)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 7th February 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

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



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


Download this snippet    Add to My Saved Code

Binary Module 1.0. This module includes functions for converting decimal numbers to binary and vice Comments

No comments have been posted about Binary Module 1.0. This module includes functions for converting decimal numbers to binary and vice. Why not be the first to post a comment about Binary Module 1.0. This module includes functions for converting decimal numbers to binary and vice.

Post your comment

Subject:
Message:
0/1000 characters