Advertisement
cd62131

Each 2 Digit to Hexadecimal Byte Sequence

Nov 24th, 2013
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.66 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class Conversion {
  8.   public static void main(String[] args) {
  9.     List<Byte> ret = new ArrayList<Byte>();
  10.     String s = "1234567890abcdef01234567890abcdef";
  11.     Pattern p = Pattern.compile("..");
  12.     Matcher m = p.matcher(s);
  13.     while (m.find()) {
  14.       char[] cs = m.group().toCharArray();
  15.       int d = 0;
  16.       for (int i = 0; i < cs.length; i++) {
  17.         d = d * 16 + Character.digit(cs[i], 16);
  18.       }
  19.       ret.add((byte )d);
  20.     }
  21.     System.out.println(Arrays.toString(ret.toArray()));
  22.   }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement