
This code snippet by SkipVought is the best on the Here is modifying it so you can optionally set the padding...
Code:
Function i2b(i, Optional p = 0)
Do
i2b = i Mod 2 & i2b
i = Fix(i / 2)
Loop Until i = 0
i = Len(i2b)
If i < p Then i2b = String(p - i, "0") & i2b