title: Convert A Large Integer To a Hex String In Javascript
body: <p>I need to find a way to convert a large number into a hex string in javascript. Straight off the bat, I tried <code>myBigNumber.toString(16)</code> but if <code>myBigNumber</code> has a very large value (eg 1298925419114529174706173) then <code>myBigNumber.toString(16)</code> will return an erroneous result, which is just brilliant. I tried writing by own function as follows:</p>
  
  <pre><code>function (integer) {
      var result = '';
  
      while (integer) {
          result = (integer % 16).toString(16) + result;
          integer = Math.floor(integer / 16);
      }
  }
  </code></pre>
  
  <p>However, large numbers modulo 16 all return 0 (I think this fundamental issue is what is causing the problem with <code>toString</code>. I also tried replacing <code>(integer % 16)</code> with <code>(integer - 16 * Math.floor(integer/16))</code> but that had the same issue.</p>
  
  <p>I have also looked at the Big Integer Javascript library but that is a huge plugin for one, hopefully relatively straightforward problem.</p>
  
  <p>Any thoughts as to how I can get a valid result? Maybe some sort of divide and conquer approach? I am really rather stuck here.</p>