「Java」Hex クラスで byte 配列を16進数文字列に変換する

2022年7月12日

必要なjar
commons-codec-1.9.jar
ダウンロード
http://commons.apache.org/proper/commons-codec/

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.arkgame.study;
import org.apache.commons.codec.binary.Hex;
public class Byte2HexDemo {
public static void main(String[] args) {
String str = "study in arkgame";
byte[] bytes = str.getBytes();
String result = new String(Hex.encodeHex(bytes));
System.out.println("Byte配列を16進数文字列に変換する結果:\n" + result);
}
}
package com.arkgame.study; import org.apache.commons.codec.binary.Hex; public class Byte2HexDemo { public static void main(String[] args) { String str = "study in arkgame"; byte[] bytes = str.getBytes(); String result = new String(Hex.encodeHex(bytes)); System.out.println("Byte配列を16進数文字列に変換する結果:\n" + result); } }
package com.arkgame.study;

import org.apache.commons.codec.binary.Hex;

public class Byte2HexDemo {

      public static void main(String[] args) {
            String str = "study in arkgame";
            byte[] bytes = str.getBytes();

            String result = new String(Hex.encodeHex(bytes));
            System.out.println("Byte配列を16進数文字列に変換する結果:\n" + result);

      }

}

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Byte配列を16進数文字列に変換する結果:
737475647920696e2061726b67616d65
Byte配列を16進数文字列に変換する結果: 737475647920696e2061726b67616d65
Byte配列を16進数文字列に変換する結果:
737475647920696e2061726b67616d65

 

Java

Posted by arkgame