Home

> urticator.net
  Search

  About This Site
> Domains
  Glue
  Stories

  Computers
  Driving
  Games
  Humor
  Law
  Math
> Numbers
  Science

  Powers and Fractions
  Notes About Squares
> Decimal Expansions
  Repeat Length Again
  Number Maze
  Primes
  Divisibility
  Intrinsic Nature of Primes
  Other Topics
  Other Topics (2)

  Other Denominators
  Repeat Length
  Complementary Parts
> Expansion Calculator
  Footnote

Expansion Calculator

I like computing things. Most of the fractions you see around here—the common ones, the larger ones, and the common ones in base 2—I worked out by hand at one time. This time, though, I got lazy and wrote some code to do it for me.

It was surprisingly simple, actually. Here's the interesting part, which fills the array q with the expansion of m/n in base b.

int a = m;
for (int i=0; i<n; i++)
{
   q[i] = a/n;
   r[i] = a = a%n;

   /* if r[i] is zero,  expansion terminates */
   /* if r[i] is a repeat, expansion repeats */

   a *= b;
}

Since I'm a bug for names, I'd like to point out that the letters “q” and “r” stand for “quotient” and “remainder”, and also that the letter “a” stands for the slightly less obvious “accumulator”.

Since I was thinking about hexadecimal, I set up the output code to handle it, producing the digits A–F for the quotient values 10–15. But then I figured, why stop there? So, I put in the whole alphabet, allowing me to work in any base up to base 36.

Then, naturally, with that many letters around, I had to start looking for words. That was pointless, I knew—you can find patterns in any kind of random (or pseudorandom) noise, if you look at enough of it. Still, it was fun for a while.

The best ones I found were in base 36 itself. That was a surprise—I had figured I'd be better off without, say, X, Y, and Z. Anyway, there were two that I really liked. One was short and to the point: 1/74 (in decimal) has expansion 0.0HI. And one was the following little gem.

1/47 = 0.0RKOIDSC96W64LG32AQ1J5D

What's really funny is, the expansion, like the expansion of 1/7 in decimal, shows up in other expansions in various rotated forms (see Fractions for more detail). So, the D at the end usually comes up to the front, and you get … D0RKOIDS!

After that, there's a strange interleaved sequence of letters and multiples of 32.

C96
W64
LG32

Even the rest of the expansion is sort of interesting. The A, Q, and J remind me of cards, and the thing as a whole looks like a license plate number.

I thought maybe I'd have better luck if I removed the numbers and worked in base 26, but I tried that, and nothing jumped out at me.

Speaking of bases, and of things where the digit A has value 0, that reminds me of something else I like. When you send a file via email, the raw bytes have to be converted into printable characters; one common way of doing that is known as base 64 encoding. The process is actually very simple. Bytes are like digits in base 256, so it's just as easy to translate them into base 64 as it is to translate hexadecimal into octal; the only question is, which characters should be used to represent which digits? Here's the standard answer.

     0123 4567 89AB CDEF

0_   ABCD EFGH IJKL MNOP
1_   QRST UVWX YZab cdef
2_   ghij klmn opqr stuv
3_   wxyz 0123 4567 89+/

It would be more natural to have the table map to octal, but what can I say, I like hexadecimal.

Finally, speaking of numbers being words, see also Speedtalk.

 

  See Also

  In Other Bases

@ April (2004)