4
1

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.

JavaとPythonで同じようにbytesを表示する方法

4
Last updated at Posted at 2018-12-28

データストアに格納したバイナリをPythonとJava(Scala)で取得や加工を行う際に、
どちらもbytesの表示のされかたが異なり比較がめんどくさかったので同様に表示される方法を調査しました。

Python

print(b"abcde".hex())

Java

printlnではbyte[]の中身を表示させることが出来ずfor文で一要素づつ表示させるとPythonと異なり符号付きになるためなかなかめんどくさかったのですが下記で同じように表示できます。

import java.math.BigInteger;

byte[] bytes = "abcde".getBytes();
System.out.printf("%x%n", new BigInteger(1, bytes));

どちらも下記のように出力されます。

6162636465
4
1
2

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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?