title: From Hex String to signed int
body: <p>In the app that I'm developing, first of all, I do a conversion from a decimal value to an hex string.</p>
  
  <p>For example, I convert the int value <strong>-100000</strong> to it's hex value:</p>
  
  <pre><code>hex_value = Integer.toHexString (-100000)
  </code></pre>
  
  <p>And I get this:</p>
  
  <pre><code>hex_value = FFFE7960
  </code></pre>
  
  <p>Now, I need to do the inverse conversion. I get the <strong>FFFE7960</strong> hex value and I need to convert it to <strong>-100000</strong> again, for this I use:</p>
  
  <pre><code>int_value = Integer.parseInt(hex_value,16)
  </code></pre>
  
  <p>But instead of getting <strong>-100000</strong>, I get <strong>4294867296</strong>.</p>
  
  <p>So, instead of getting the signed int value, I'm getting a unsigned value that causes an error on my app. </p>
  
  <p>How can I do it to get the desired value?</p>
  
  <p><strong>UPDATE - FULL CODE</strong></p>
  
  <p>This is the string that I receive via bluetooth:</p>
  
  <pre><code>s = "2b 00 ff fe 79 60"
  </code></pre>
  
  <p>With the StringTokenizer I split it:</p>
  
  <pre><code>StringTokenizer tokens = new StringTokenizer(s," ");
  String one = tokens.nextToken();
  String two = tokens.nextToken();
  String three = tokens.nextToken();
  String four = tokens.nextToken();
  String five = tokens.nextToken();
  String six = tokens.nextToken();
  
  received_hexValue = three + four + five + six;
  </code></pre>
  
  <p>So, <strong>received_hexValue = "fffe7960"</strong></p>
  
  <p>Now, I make the conversion that I need:</p>
  
  <pre><code>int_value_receive = (int)Long.parseLong(received_hexValue, 16);
  int_value_receive = -200000 - int_value_receive;
  newIntValue = (int_value_receive * 100) / (200000 * (-1));
  </code></pre>
  
  <p>In the first line, when converting from hex to int, the debugger throws me a Long.invalidLong(String) error, and in the logcat, shows the error commented: java.lang.NullPointerException</p>