title: Simulating unsigned number with a certain power of two max in java
body: <p>I have some output from a (C++) application that stores a tickcount value in a type that wraps to zero at 2<sup>33</sup>. (8,589,934,592) (Don't have the code)</p>
  
  <p>I need to write my own output in the same way. I retrieve the tickcount from a C lib through JNA, but if I store it in an int it wraps to -2<sup>31</sup> (-2,147,483,648) after ~25 days' tickcount and if I store it in a long it just keeps going past 2<sup>33</sup>. </p>
  
  <p>How can I store (or write) the value in Java in such a way that it wraps (to zero) at 2<sup>33</sup>? </p>
  
  <p>(Preferably a JRE7- &amp; JRE8- on Win32- &amp; Win64- &amp; Linux-compatible solution)</p>
  
  <p>To get the tickcount I use the following:</p>
  
  <pre><code>import com.sun.jna.*;
  public interface Kernel32 extends Library {
      Kernel32 INSTANCE = (Kernel32) Native.loadLibrary((Platform.isWindows() ? "kernel32" : "c"), Kernel32.class);
  
      /**
       * Retrieves the number of milliseconds that have elapsed since the system was started.
       *
       * @return number of milliseconds that have elapsed since the system was started.
       * @see http://msdn2.microsoft.com/en-us/library/ms724408.aspx
       */
      Long GetTickCount();
  }
  
  public interface Clib extends Library {
      Clib INSTANCE = (Clib) Native.loadLibrary((Platform.isWindows() ? "kernel32" : "c"), Clib.class);
  
      /**
       * Retrieves the number of milliseconds that have elapsed since the system was started.
       *
       * @return number of milliseconds that have elapsed since the system was started.
       */
      Long clock();
  }
  
  // And later
  Number n = (Platform.isWindows() ? Kernel32.INSTANCE.GetTickCount() : Clib.INSTANCE.clock()).toString());
  </code></pre>