There is a celebrated formula (perhaps BBP?) that allows you to calculate an arbitrary hexadecimal digit of the expansion of $\pi$. That takes care of bases $4,32,128$.
Now any other formula that is used to calculate $\pi$ in decimal, actually calculates $\pi$ in binary, the result being converted to decimal using the simple base-conversion algorithm. So you can use any old formula, say the arc-tangent one.
Finally, there's probably somewhere on the web an expansion of $\pi$ to zillions of binary digits. Moreover, someone probably wrote a program that converts from binary to an arbitrary base. So all you need to do is find these and plug them together.
J is very useful. While it has its quirks, once you get used to them, as gar said, you can really understand the language quite well. I consider myself a novice at J, but being exposed to it, I can definitely tell what the example in the accepted answer's "mysterious code". It's easy enough to say you don't know what a program does, that's the same for many languages.
I for one cannot understand, without running it, some C programs, especially ones that rely on pointers, me being mainly a JavaScript programmer. Does that make C useless and unreadable? Granted, J has a higher scale of unreadability, but it still can be readable. There's a line between readable and unreadable, and J lies right on the line.
As for your question, I believe it is very useful for math (I use it for geometry) and mathematicians (it's a nice calculator if you have a computer with you, and are used to it). While you may not appreciate J, I strongly suggest you try learning it. J, APL, etc. can seem like a bunch of nonsense, but it's just another way to program and to learn.
You can stop reading if you're convinced—I'm mainly showing examples now.
J is good for its conciseness. You want a multiplication table for numbers 0
to 10
? Boom:
*/~i.11
This yields a very appealing table:
0 0 0 0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 7 8 9 10
0 2 4 6 8 10 12 14 16 18 20
0 3 6 9 12 15 18 21 24 27 30
0 4 8 12 16 20 24 28 32 36 40
0 5 10 15 20 25 30 35 40 45 50
0 6 12 18 24 30 36 42 48 54 60
0 7 14 21 28 35 42 49 56 63 70
0 8 16 24 32 40 48 56 64 72 80
0 9 18 27 36 45 54 63 72 81 90
0 10 20 30 40 50 60 70 80 90 100
Want to make it look like a "real" multiplication table (without the zero columns)? No problem:
*/~1+i.10
While this looks like a bunch of jargon to the casual observer, it makes a great deal of sense. Observe:
*/~ 1 + i. 10
i. n
makes an integer range $[0, n)$. 1 + i. n
creates an integer range $[1, n]$. ~
makes a one-argument function (or monad) take its argument twice, making it a two-argument function (or dyad). E.g., +~ n = n + n
and *~ n = n * n
or n^2
.
/
inserts the function before it (*
/multiplication) between every member (so +/
is summation over a list), or, when having two arguments as in +/~
, it essentially makes a table in our desired fashion.
While this is only a bit of J, you can see the effect it has for its brevity. It makes calculation swifter and easier—so long as you devote the time to learning it. Which I suggest you do.
Best Answer
I have used PARI/GP for decades. It is very easy to use and very capable of arbitrary precision computations. It is GPL software which means it is free to download from source as well as a standalone Windows executable. More information is available on their website. For your intended use, it has several bit oriented operations on integers, including for example: