Advertisement
top_wizard

StringUtils java

Dec 11th, 2014
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. package javaapplication1;
  2. import java.io.UnsupportedEncodingException;
  3.  
  4. public class StringUtils {
  5.     static final byte[] HEX_CHAR_TABLE={
  6.         (byte)'0',(byte)'1',(byte)'2',(byte)'3',(byte)'4',(byte)'5',(byte)'6',
  7.         (byte)'7',(byte)'8',(byte)'9',(byte)'a',(byte)'b',(byte)'c',(byte)'d',
  8.         (byte)'e',(byte)'f'
  9.     };
  10.     public static String getHexString (byte[] raw)
  11.             throws  UnsupportedEncodingException {
  12.         byte[] hex=new byte[2*raw.length];
  13.         int index=0;
  14.         for (byte b:raw){
  15.             int v=b&0xFF;
  16.             hex[index++]=HEX_CHAR_TABLE[v>>>4];
  17.             hex[index++]=HEX_CHAR_TABLE[v&0xF];
  18.         }
  19.         return new String(hex,"ASCII");
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement