title: Exception while Parsing Hexadecimal to Short in Java
body: <p>In file data.hex, the data is given in hexadecimal form where the first digit of hexadecimal number is always less than 8. Eg.</p>
  
  <pre><code>01FC 04BF 04C0 04C1 04C2 24C3 04C4 34C5 ...
  </code></pre>
  
  <p>To parse this file and store the values in shrt[] array i have written this code</p>
  
  <pre><code>void read_hex_short(String filename, short[] shrt, int x, int y) throws Exception
  {
      String str;
      Scanner s=new Scanner(new BufferedReader(new FileReader(filename)));
      for(int i=0;i&lt;height*width;i++)
      {
          str= s.next();    // i have tried str="0x"+s.next() but it didn't work
          image[i]=(short)Integer.parseInt(str);
      }
      s.close();
  }
  </code></pre>
  
  <p>But i am getting NumberFormatException  which arises while passing the first string i.e. 01FC only. 
  How can i parse these hexadecimal values and store them in the shrt[] array?</p>