VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



I made these functions to convert ASCII to Binary, Binary to ASCII, Decimal to Binary and Binary to

by Darren Tully (1 Submission)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 2nd June 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)

I made these functions to convert ASCII to Binary, Binary to ASCII, Decimal to Binary and Binary to Decimal.

Rate I made these functions to convert ASCII to Binary, Binary to ASCII, Decimal to Binary and Binary to



Dim BinAsc As String
Dim BinDec(7, 1) As String
Dim AscBin As String

Public Function DectoBin(Number As Double)
    For i = 0 To 7
        Number = Number / 2
        If Number - Fix(Number) = 0.5 Then
            Bin(i) = 1
        Else
            Bin(i) = 0
        End If
        If Number - Fix(Number) = 0.5 Then
            Number = Number - 0.5
        End If
    Next i
    DectoBin = Bin(7) & Bin(6) & Bin(5) & Bin(4) & Bin(3) & Bin(2) & Bin(1) & Bin(0)
End Function

Public Function BintoDec(BinNum As String)
    Dec = 0
    For i = 0 To 7
        power = 2 ^ i
        BinDec(7 - i, 0) = power
    Next i
    For i = 0 To 7
        BinDec(i, 1) = Mid(BinNum, i + 1, 1)
    Next i
    For i = 0 To 7
        If BinDec(i, 1) = 1 Then
            Dec = Dec + BinDec(i, 0)
        End If
    Next i
    BintoDec = Dec
End Function

Public Function AsctoBin(aString As String)
    BinAsc = ""
    For it = 1 To Len(aString)
        BinAsc = BinAsc & DectoBin(Asc((Mid(aString, it, 1))))
    Next it
    AsctoBin = BinAsc
End Function

Public Function BintoAsc(bString As String)
    AscBin = ""
    For it = 1 To Len(bString) Step 8
        AscBin = AscBin & Chr(BintoDec(Mid(bString, it, 8)))
    Next it
    BintoAsc = AscBin
End Function

Download this snippet    Add to My Saved Code

I made these functions to convert ASCII to Binary, Binary to ASCII, Decimal to Binary and Binary to Comments

No comments have been posted about I made these functions to convert ASCII to Binary, Binary to ASCII, Decimal to Binary and Binary to. Why not be the first to post a comment about I made these functions to convert ASCII to Binary, Binary to ASCII, Decimal to Binary and Binary to.

Post your comment

Subject:
Message:
0/1000 characters