Option ExplicitFunction Bin2Dec(InputData As String) As Double
''
''  This converts Binary to Decimal
''
Dim DecOut As Double
Dim I As Integer
Dim LenBin As Double
Dim JOne As StringLenBin = Len(InputData)''
''  Make sure that it is a Binary Number
''
For I = 1 To LenBin
 JOne = Mid(InputData, I, 1)
   If JOne <> "0" And JOne <> "1" Then
     MsgBox "NOT A BINARY NUMBER", vbCritical
     Exit Function
   End If
Next I
DecOut = 0
For I = Len(InputData) To 1 Step -1
  If Mid(InputData, I, 1) = "1" Then
    DecOut = DecOut + 2 ^ (Len(InputData) - I)
  End If
Next I
        
  Bin2Dec = DecOut
        
End FunctionFunction Dec2Bin(InputData As Double) As String
''
''  Converts Decimal to Binary
''  This uses the Quotient Remainder method
''
Dim Quot As Double
Dim Remainder As Double
Dim BinOut As String
Dim I As Integer
Dim NewVal As Double
Dim TempString As String
Dim TempVal As Double
Dim BinTemp As String
Dim BinTemp1 As String
Dim PosDot As Integer
Dim Temp2 As String
''  Check to see if there is a decimal point or not
''
If InStr(1, CStr(InputData), ".") Then
  MsgBox "Only Whole Numbers can be converted", vbCritical
  GoTo eds
End IfBinOut = ""
NewVal = InputData
DoAgain:''  Start the Calculations off
NewVal = (NewVal / 2)
''  If we have a remainder
If InStr(1, CStr(NewVal), ".") Then
  BinOut = BinOut + "1"
  
  '' Get rid of the Remainder
  NewVal = Format(NewVal, "#0")
  NewVal = (NewVal - 1)
  
   If NewVal < 1 Then
     GoTo DoneIt
   End If
Else
  BinOut = BinOut + "0"
   If NewVal < 1 Then
     GoTo DoneIt
   End If
End If
GoTo DoAgainDoneIt:
'MsgBox BinOut
BinTemp = ""''  Reverse the Result
For I = Len(BinOut) To 1 Step -1
 BinTemp1 = Mid(BinOut, I, 1)
 BinTemp = BinTemp + BinTemp1
Next IBinOut = BinTemp'' Output the Result
Dec2Bin = BinOut
eds:
End FunctionPublic Function LR(InputData As Integer, Mode As Boolean) As Integer
    Dim BufStr As String
    Dim TarStr As String
    
    If InputData > 255 Or InputData < 0 Then
        MsgBox "Error in Input Data!"
        Exit Function
    End If
    
    BufStr = Dec2Bin(CDbl(InputData))
    If Len(BufStr) < 8 Then BufStr = String(8 - Len(BufStr), "0") + BufStr
    If Mode Then ' Left
        TarStr = Right(BufStr, 7) + "0"
    Else 'Right
        TarStr = "0" + Left(BufStr, 7)
    End If
        
    LR = CInt(Bin2Dec(TarStr))
End Function'使用
LR(255,True) 255左移一位
LR(255,False) 255右移一位