13
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

バイト配列を16進数の文字列に変換する

Last updated at Posted at 2016-03-18

#byte型配列の記載例

大文字にしたかったので"%02x"じゃなくて"%02X"としています。

        byte[] array = hoge();  // byte配列を返すメソッドのつもり
        StringBuilder sb = new StringBuilder();
        for (byte d : array) {
            sb.append(String.format("%02X", d));
        }
        String str = sb.toString();

#Byte型配列の記載例

ご指摘をいただいたので追記しました。

        Byte[] array = hoge();  // Byte配列を返すメソッドのつもり
        String str = Arrays.stream(array)
                .map(b -> String.format("%02X", b))
                .collect(Collectors.joining());
13
11
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?