SPUG: Cool power-of-2 trick
Michael R. Wolf
MichaelRWolf at att.net
Thu Jan 20 13:30:28 PST 2005
At 12:29 PM 1/20/2005, Brian Hatch wrote:
> > While reading through the perl-quiz-of-the-week, I noticed this neat test
> > to find if a number is a power of 2. Originally, I didn't even believe it
> > worked so I wrote a little program to test it. The program helped me
> > figure out that it does, in deed, work, and *how* it works. If a
> number is
> > a pure powere of 2, it only has one bit set.
>...
>
>
>This only works on systems where data is stored in binary. If you're on
>a machine that uses ternary storage units (-1 0 +1) then it does not
>work for powers of two, but it does work for powers of three.
>
>Of course I'm still waiting for the completely optimal system which uses
>storage units of 'e' instead of rounding to 3 for simplicity.
In a grad school EE/CS class, the professor did a proof on the board that
the best computer would, in fact, have each storage unit contain e (approx
2.718281828....?) states. Since that's closer to 3 than 2, it would be
better to have a trinary system instead of a binary system. And yes, it
was hard for him to continually say trits (instead of bits) without
scrambling it up!
:-) -8
To muck with an old punch line -- You silly Rabbi, trits are for kids!!!!
Michael R. Wolf
All mammals learn by playing!
MichaelRWolf at att.net
More information about the spug-list
mailing list