Advertisement
Guest User

Func HexVal

a guest
Nov 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1.     private static String convertToHexValue(String lit) {
  2.         StringBuilder s = new StringBuilder();
  3.         if (lit.startsWith("=C")) {
  4.             lit = lit.replace("=C'", "").replace("'", "");
  5.             for (char ch : lit.toCharArray()) {
  6.                 s.append(String.format("%x", (int) ch));
  7.             }
  8.         } else if (lit.startsWith("=X")) {
  9.             lit = lit.replace("=X'", "").replace("'", "");
  10.             for (int i = 0; i < lit.length(); i += 2) {
  11.                 String str = lit.substring(i, i + 2);
  12.                 s.append((char) Integer.parseInt(str, 16));
  13.             }
  14.         }
  15.         String hexValueOfLiteral = s.toString().toUpperCase();
  16.        
  17.         return hexValueOfLiteral;
  18.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement