title: how to convert integer to hex signed 2's complement:
body: <p>Pretty basic stuff i am sure but bits are not my forte.</p>
  <p>So for some internal calculation i am trying to convert a given input ( constraint is that it would be a integer string for sure) into its hex equivalent, what stumped me is on how to get
  Hex signed 2's complement:</p>
  <p>My noob code:</p>
  <pre><code>   private String toHex(String arg, boolean isAllInt) {
          String hexVal = null;
          log.info(&quot;arg {}, isAllInt {}&quot;, arg, isAllInt);
          if (isAllInt) {
              int intVal = Integer.parseInt(arg);
              hexVal = Integer.toHexString(intVal);
              // some magic to convert this hexVal to its 2's compliment
          } else {
              hexVal = String.format(&quot;%040x&quot;, new BigInteger(1, arg.getBytes(StandardCharsets.UTF_8)));
          }
          log.info(&quot;str {} hex {}&quot;, arg, hexVal);
          return hexVal;
      }
  </code></pre>
  <p>Input: 00001 <br />
  Output: 1<br />
  Expected Output: 0001<br /></p>
  <p>Input: 00216 <br />
  Output: D8<br />
  Expected Output: 00D8<br /></p>
  <p>00216</p>
  <p>Input: 1192633166<br />
  Output: 4716234E<br />
  Expected Output: 4716234E<br /></p>
  <p>any predefined library is much welcome or any other useful pointers!</p>