'Usage: Bin2Dec(BINARY HERE) (returns decimal number)
Function Bin2Dec(ByVal sBinary As String) As Long
For i = 0 To Len(sBinary) - 1
If Mid(sBinary, Len(sBinary) - i, 1) = "1" Then Bin2Dec = Bin2Dec + (2 ^ i)
Next
End Function
'Usage: Dec2Bin(NUMBER HERE) (returns binary)
Public Function Dec2Bin(myNum As Variant) As String
Dim loopcounter As Integer
If myNum >= 2 ^ 31 Then
Dec2Bin = "Too big"
Exit Function
End If
Do
If (myNum And 2 ^ loopcounter) = 2 ^ loopcounter Then
Dec2Bin = "1" & Dec2Bin
Else
Dec2Bin = "0" & Dec2Bin
End If
loopcounter = loopcounter + 1
Loop Until 2 ^ loopcounter > myNum
If Len(Dec2Bin) / 2 <> Int(Len(Dec2Bin) / 2) Then Dec2Bin = "0" & Dec2Bin
End Function
Public Function ExtendedAsc(Byte1 As String, Byte2 As String) As Long
Dim Bytes As String
Bytes = Dec2Bin(Asc(Byte1)) & Dec2Bin(Asc(Byte2))
ExtendedAsc = Bin2Dec(Bytes)
End Function