title: Working with hex strings and hex values more easily in Javascript
body: <p>I have some code which takes strings representing hexadecimal numbers - hex colors, actually - and adds them. For example, adding <code>aaaaaa</code> and <code>010101</code> gives the output <code>ababab</code>.<br>
  However, my method seems unnecessarily long and complicated:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var hexValue = "aaaaaa";
  hexValue = "0x" + hexValue;
  hexValue = parseInt(hexValue, 16);
  hexValue = hexValue + 0x010101;
  hexValue = hexValue.toString(16);
  document.write(hexValue); // outputs 'ababab'</code></pre>
  </div>
  </div>
  </p>
  <p>The hex value is still a string after concatenating <code>0x</code>, so then I have to change it to a number, <em>then</em> I can add, and then I have to change it <em>back</em> into hex format! There are even more steps if the number I'm adding to it is a hexadecimal string to begin with, or if you take into consideration that I am removing the <code>#</code> from the hex color before all this starts.</p>
  <p>Surely there's a simpler way to do such simple hexadecimal calculations! And just to be clear, I don't mean just putting it all on one line like <code>(parseInt(&quot;0x&quot;+&quot;aaaaaa&quot;,16)+0x010101).toString(16)</code> or using shorthand - I mean actually doing less operations.</p>
  <p>Is there some way to get javascript to stop using decimal for all of its mathematical operations and use hex instead? Or is there some other method of making JS work with hex more easily?</p>