It will convert decimal integer values to a binary string, you also have the option to set the number of bits the function returns, by default the function will return 8 bits.
For example:
Code: Select all
Dim myDec As Integer
myDec = 146
textbox1.Text = DecToBin(myDec)
' will return Binary 10010010
Code: Select all
Dim myDec As Integer
myDec = 146
textbox1.Text = DecToBin(myDec, 16)
' will return Binary 0000000010010010
Code: Select all
Public Function DecToBin(ByVal DeciValue As Long, Optional ByVal NoOfBits As Integer = 8) As String
Dim i As Integer
Do While DeciValue > (2 ^ NoOfBits) - 1
NoOfBits = NoOfBits + 8
Loop
DecToBin = vbNullString
For i = 0 To (NoOfBits - 1)
DecToBin = CStr((DeciValue And 2 ^ i) / 2 ^ i) & DecToBin
Next i
End Function