Public Function Dec2Bin(DecVal)
Dim bits, Dec As String
Dec = DecVal 'The decimal value
If Dec >= 128 Then bits = "1": Dec = Dec - 128 Else bits = "0"
If Dec >= 64 Then bits = bits & "1": Dec = Dec - 64 Else bits = bits & "0"
If Dec >= 32 Then bits = bits & "1": Dec = Dec - 32 Else bits = bits & "0"
If Dec >= 16 Then bits = bits & "1": Dec = Dec - 16 Else bits = bits & "0"
If Dec >= 8 Then bits = bits & "1": Dec = Dec - 8 Else bits = bits & "0"
If Dec >= 4 Then bits = bits & "1": Dec = Dec - 4 Else bits = bits & "0"
If Dec >= 2 Then bits = bits & "1": Dec = Dec - 2 Else bits = bits & "0"
If Dec >= 1 Then bits = bits & "1": Dec = Dec - 1 Else bits = bits & "0"
If Dec > 0 Then
Dec2Bin = "11111111"
Else
Dec2Bin = bits
End If
End Function

To extract a bit -

Public Function ExtractBit(Dec, mybit)
Dim bit(8), DecVal As Integer
DecVal = Dec
If DecVal >= 128 Then bit(7) = 1: DecVal = DecVal - 128 Else bit(7) = 0
If DecVal >= 64 Then bit(6) = 1: DecVal = DecVal - 64 Else bit(6) = 0
If DecVal >= 32 Then bit(5) = 1: DecVal = DecVal - 32 Else bit(5) = 0
If DecVal >= 16 Then bit(4) = 1: DecVal = DecVal - 16 Else bit(5) = 0
If DecVal >= 8 Then bit(3) = 1: DecVal = DecVal - 8 Else bit(5) = 0
If DecVal >= 4 Then bit(2) = 1: DecVal = DecVal - 4 Else bit(5) = 0
If DecVal >= 2 Then bit(1) = 1: DecVal = DecVal - 2 Else bit(5) = 0
If DecVal >= 1 Then bit(0) = 1: DecVal = DecVal - 1 Else bit(5) = 0
If DecVal > 0 Then
ExtractBit = -1
Else
ExtractBit = bit(mybit)
End If
End Function