1 2 24 25 package com.lutris.util; 26 27 34 public class HexEncoder { 35 38 private static final char[] HexChars = { 39 '0', '1', '2', '3', '4', '5', '6', '7', 40 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' 41 }; 42 43 56 public static final String toHexString(long value, int len, char pad) { 57 StringBuffer sb = new StringBuffer (Long.toHexString(value)); 58 int npad = len - sb.length(); 59 while (npad-- > 0) sb.insert(0, pad); 60 return new String (sb); 61 } 62 63 73 public static final String toHexString(byte[] bytes) { 74 StringBuffer sb = new StringBuffer (); 75 int i; 76 for (i=0; i < bytes.length; i++) { 77 sb.append(HexChars[(bytes[i] >> 4) & 0xf]); 78 sb.append(HexChars[bytes[i] & 0xf]); 79 } 80 return new String (sb); 81 } 82 } 83 84 85 | Popular Tags |