How to calculate orders of magnitude using a new base?

47 Views Asked by At

I am trying to think of a different way to encode time in software (for a fantasy world), and am currently imagining starting from the second and going up in -- I don't know what to call it -- "chunks" or "powers" of $2^{16}$ (65536). So you have:

  • 1 second (call it $s_1$)
  • $2^{16}$ $s_1$ (call this unit $s_2$ instead of something like "minute")
  • $2^{16}$ $s_2$ (call it $s_3$)
  • $2^{16}$ $s_3$ (call it $s_4$)
  • etc.

Then likewise down in scale from the second by the same amount (I'm not sure how to do that exactly, I think that would just be a fraction like $\frac{1}{2^{16}}$ or $2^{-16}$?)

How do I then convert a standard time time frame to this sort of system? Say we are representing 1 billion years (1 billion * 365 * 86400 seconds in a day = 3.1536e+16). How would you convert that into numbers of $s_3$ and $s_2$ and $s_1$, etc.? What is the general strategy for converting between these types of systems? I think it would be called having a new base (instead of base 10, we have base $2^{16}$), but I'm not super familiar with that. So basically I think this question boils down to how do you do the "base" calculations in a generic way, and then showing how to apply it to an (arbitrary) new situation like this?

I say arbitrary new situation, because I might end up changing the base values and such, so would like to know how to apply it in a generic way.

If it is at all useful (I don't know, maybe it's TMI), I would then encode this in compact bits. So say we went up to $s_5$. That would be 16-16-16-16-16 bits (where 16 is 16 bits). So in my mind I can kind of see how the further to the left you go, the higher "order of magnitude" you would go, and yet it would all be compiled together to one final value in lets say nanoseconds.

1

There are 1 best solutions below

6
On BEST ANSWER

Let the regular time in seconds to be $t$ then, $$s_n=\left\lfloor\frac{t \mod 2^{16(n+1)}}{2^{16n}}\right\rfloor$$

Or, alternatively, as @Jaap Scherphuis said in the comment below, $$s_n=\left\lfloor\frac{t }{2^{16n}}\right\rfloor\mod 2^{16}$$