星期三, 7月 09, 2008

Hex String to Byte Array and reverse

A very easy way to do these 2 things.

import java.math.*;

public String toHexString(byte[] in){
BigInteger temp = new BigInteger(in);
return temp.toString(16);
}

public byte[] fromHexString(String in){
BigInteger temp = new BigInteger(in, 16);
return temp.toByteArray();
}

沒有留言: