fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12.  
  13. String hexValue = "73657269616C6E6F80";
  14. String binValue = hexStringToBin(hexValue);
  15.  
  16. System.out.println("binValue : " + binValue);
  17.  
  18. int index = binValue.lastIndexOf(0x80);
  19.  
  20. System.out.println("index : " + index);
  21. }
  22.  
  23. public static String hexStringToBin(String s) {
  24. int len = s.length();
  25. byte[] data = new byte[len / 2];
  26.  
  27. for (int i = 0; i < len; i += 2) {
  28. data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
  29. }
  30.  
  31. return new String(data);
  32. }
  33. }
Success #stdin #stdout 0.09s 27864KB
stdin
Standard input is empty
stdout
binValue : serialno�
index : -1