LoginSignup
0
0

More than 5 years have passed since last update.

string.getByte()とHex.decodeHex(string.toCharaArray())の違い

Last updated at Posted at 2018-10-23

string.getByte()とHex.decodeHex(string.toCharaArray())はどちらもstring文字列をbyte[]型に変換する処理ですが、少し違いがあります。

string.getByte()
普通の文字列をbyte[]型に変換する。
変換後のbyte長はhexで変換した場合のbyte長の2倍になります。

Hex.decodeHex(string.toCharaArray())
16進数にダブルクォーテーションをつけた文字列(要するにString型だけど中身のデータは16進数である文字列)をbyte型に変換する。

では、変換する文字列が「1」や「a」のような16進数か普通の文字か一見区別がつかない文字列を両方の処理をするとどうなるのか。

結果としては、それぞれで異なるbyte[]型文字列が生成されます。

0
0
0

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
0
0