[New] Added StringHelper.asHexString()
This commit is contained in:
parent
53e4d5ce87
commit
7febff0de7
|
@ -56,6 +56,10 @@ public class StringHelper {
|
||||||
(byte) '5', (byte) '6', (byte) '7', (byte) '8', (byte) '9', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd',
|
(byte) '5', (byte) '6', (byte) '7', (byte) '8', (byte) '9', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd',
|
||||||
(byte) 'e', (byte) 'f' };
|
(byte) 'e', (byte) 'f' };
|
||||||
|
|
||||||
|
public static String asHexString(byte data) {
|
||||||
|
return String.format("%02x", data);
|
||||||
|
}
|
||||||
|
|
||||||
public static String asPrettyHexString(byte[] raw) {
|
public static String asPrettyHexString(byte[] raw) {
|
||||||
try {
|
try {
|
||||||
byte[] hex = new byte[3 * raw.length + (raw.length / 8)];
|
byte[] hex = new byte[3 * raw.length + (raw.length / 8)];
|
||||||
|
@ -81,10 +85,6 @@ public class StringHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
System.out.println(asPrettyHexString(fromHexString("010000000000040003000000000000c0")));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts each byte of the given byte array to a HEX value and returns the concatenation of these values
|
* Converts each byte of the given byte array to a HEX value and returns the concatenation of these values
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue