title: Divide a 48-bit number which is composed of a 16bit and a 32bit variable
body: <p>I am developing a software for an embedded microcontroller (STN1110). It has no FPU or SFP emulation. </p>
  
  <p>There is an SDK method which returns the uptime of the controller in microseconds, split in two variables: uint16 (msw) and uint32 (lsw). </p>
  
  <p>I want to convert this "pair" into a single uint32 with seconds precision (<code>/ 1000 / 1000</code>).</p>
  
  <p>The SDK API docs state the following:</p>
  
  <pre><code>uint32 TimeGet48 (uint16 * time_msw)
  -----------------------------------------   
  Read the current full 48-bit system time.
  
  Returns all 48 bits of the current value of the system's 1MHz clock. The resolution of the returned 32 bit value is one microsecond, with the most significant word returned through the pointer passed as a parameter. The clock therefore wraps after approximately 8.9 years. That should be enough for most purposes.
  
  Parameters:
  - time_msw: A pointer to store the most significant word of the current system time
  Returns:
  - Lower 32 bits to the current system time.
  </code></pre>
  
  <p>The main problem here is, the controller supports only up to <code>uint32</code>, so no <code>uint64</code>. </p>
  
  <p>I "glued" some code together that I thought may be the solution. It is not, as there are errors as soon as the uint16 value is > 0 and I'm not able to find it. </p>
  
  <pre><code>uint32 divide(uint32 time_in_us_lsb, uint16 time_in_us_msb, uint32 divisor)
  {
      uint32 value1 = (uint32)time_in_us_msb &amp; 0xFFFF;
      uint32 value2 = (uint32)(time_in_us_lsb &gt;&gt; 16) &amp; 0xFFFF;
      uint32 value3 = (uint32)time_in_us_lsb &amp; 0xFFFF;
  
      value2 += (value1 % divisor) &lt;&lt; 16;
      value3 += (value2 % divisor) &lt;&lt; 16;
  
      return (((value2 / divisor) &lt;&lt; 16) &amp; 0xFFFF0000) | ( value3 / divisor);
  }
  
  uint32 getUptimeSeconds() {
      uint32 time_in_us_lsb;
      uint16 time_in_us_msb;
  
      time_in_us_lsb = TimeGet48(&amp;time_in_us_msb);   
      uint32 result = divide(time_in_us_lsb, time_in_us_msb, 100000);
  
      time_in_us_lsb = (uint32)result &amp; 0xFFFFFFFF;
      time_in_us_msb = 0;
  
      return divide(time_in_us_lsb, time_in_us_msb, 10); 
  }
  </code></pre>
  
  <p>Note: Speed is not an issue here, as the function will not be called often during the applications lifetime.</p>
  
  <p>Edit: Added the <code>uint32</code> capability limit. </p>