Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Int to Bin 2021

Status
Not open for further replies.

DataPaper

Technical User
Dec 3, 2019
2
CA
Screenshot_2021-10-01_03-50-07-631_xwabbd.png


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
 
and going the other way...

Code:
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
 
How time flies when yer havin' fun! And it was a fun exercise back, what, over a decade ago.

Well Gates & Co now have base conversion functions (decimal to binary, octal, hexadecimal and back), just without the Reverse feature, which was only there for that original poster's requirement. The functions are part of the MS360 suite of features in Excel, so I'm not sure they're accessible in Access.

There's also a DECIMAL() function that can convert a TEXT representation of a number in any base to decimal, where you supply the appropriate radix value.

And, as you'd expect, a BASE() function that converts a decimal to a value representation in any base such that 3 base 3 [BASE(3, 3)], would be represented as 10.

So, then, progress has caught us both and left us coughing in its dust trying to keep abreast.


Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top