How to convert a byte into Hexadecimal in Java

0 votes
I have an array of bytes and I want to convert it into corresponding hexadecimal values. Is there a function to perform this?
Aug 21, 2018 in Java by Sushmita
• 6,920 points
2,960 views

2 answers to this question.

0 votes
byte[] bytes = {-1, 0, 1, 2, 3 };
    StringBuilder sb = new StringBuilder();
    for (byte b : bytes) {
        sb.append(String.format("%02X ", b));
    }
    System.out.println(sb.toString());
    // prints "FF 00 01 02 03 "
answered Aug 21, 2018 by Parth
• 4,640 points