Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows
Visual Basic > Code Snippets sample source codes
Binary to decimal and decimal to binary conversions
Binary to decimal and decimal to binary conversions Public Function BinaryToDecimal(Binary As String) As Long Dim n As Long Dim s As Integer For s = 1 To Len(Binary) n = n + (Mid(Binary, Len(Binary) - s + 1, 1) * (2 ^ (s - 1))) Next s BinaryToDecimal = n End Function Public Function DecimalToBinary(DecimalNum As Long) As String Dim tmp As String Dim n As Long n = DecimalNum tmp = Trim(Str(n Mod 2)) n = n \ 2 Do While n <> 0 tmp = Trim(Str(n Mod 2)) & tmp n = n \ 2 Loop DecimalToBinary = tmp End Function
Privacy Policy
|
Link to Us
|
Links