and going the other way...
Function b2d(b)
n = InStr(1, b, "1")
b = Mid(b, IIf(n = 0, 1, n))
n = Len(b) - 1
For c = 0 To n
b2d = b2d + 2 ^ (n - c) * Mid(b, c + 1, 1)
Next c
End Function
NOTE: Trims leading 0's
This code snippet by SkipVought is the best on the www IMO. Here is modifying it so you can optionally set the padding...
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.