Convert byte Array To Hex String
public class Main {
public static void main(String arg[]) {
String s = byteArrayToHexString(("abc").getBytes());
System.out.println(s);
}
public static String byteArrayToHexString(byte[] b) {
StringBuffer sb = new StringBuffer(b.length * 2);
for (int i = 0; i < b.length; i++) {
int v = b[i] & 0xff;
if (v < 16) {
sb.append('0');
}
sb.append(Integer.toHexString(v));
}
return sb.toString().toUpperCase();
}
}
Output:
616263
Home
Java Book
Runnable examples
Java Book
Runnable examples
Data Type Byte:
- Create Byte from byte value
- Convert byte to String using Byte.toString method
- Convert byte to String: Using concatenation with an empty String
- Convert byte to String: Creating a byte array and passing it to the String constructor
- Convert Byte array to Int
- Convert byte[] array to String
- Content byte[] array to hex string
- Convert data to byte array back and forth
- Min and Max values of byte
- Convert Byte to primitive data types
- Convert a byte to it's hexadecimal equivalent
- Convert byte Array To Hex String
- Shift byte left
- Shift byte right
- UnSign shift byte right