public class hiHex extends Object
データを16進表示します
// バイト配列を表示 byte[] dataX= {0x02,0x7C,0x3A,0x60,(byte)0xA5}; System.out.println("data="+hiU.str(dataX)); // hiU.strでの表示 ⇒ data=[0x02, 0x7c, 0x3a, 0x60, 0xa5] System.out.println("data="+hiHex.str(dataX)); ⇒ data=027C3A60A5 System.out.println("data="+hiHex.str(dataX,"xxxx ")) ⇒ data=027c 3a60 a5 // primitive数値を表示 byte by=(byte)0xAB15C;short sh=(short)0xAB15C;int in=0xAB15C;long lo=0xAB15C; System.out.println(hiHex.str(by)+","+hiHex.str(sh)+","+hiHex.str(in)+","+hiHex.str(lo)); ⇒ 5C,B15C,000AB15C,00000000000AB15C
16進表示からbyte配列を得ます
String hexStr="01A8 780A 662C"; byte[] dataX= hiHex.toBytes(hexStr); System.out.println(hiU.str(dataX)) ⇒ [0x01, 0xa8, 0x78, 0x0a, 0x66, 0x2c]
バイト配列に対する細かな操作がhiBytes
に用意されています。
修飾子とタイプ | フィールドと説明 |
---|---|
static String[] |
graphHexByteStrs |
static int |
HEX_MAX_LEN
16進数文字列変換時の最大長のデフォルト.
|
static String[] |
hexByteStrs |
static String[] |
hexByteStrsSmall |
static char[] |
hexChars |
static char[] |
hexCharsSmall |
コンストラクタと説明 |
---|
hiHex() |
修飾子とタイプ | メソッドと説明 |
---|---|
static byte[] |
base64toBytes(String base64_)
base64文字列からbyte配列を得る.
|
static String |
bytesToBase64(byte[] data_)
byte列からbase64文字列を得る
次の作業と同等です
String base64Text= Base64.getEncoder().encodeToString(data_); |
static String |
byteStr(int i_)
バイトの16進文字列(0-9A-F:2文字)を得る.
|
static String |
byteStrSmall(int i_)
バイトの16進文字列(0-9a-f:2文字)を得る.
|
static int |
encodeHex(String hexStr_,
byte[] buf_,
int offset_,
int len_)
16進文字列をバイナリにしてbyte配列にセットする(試験中).
|
static char |
halfByteChar(int i_)
ハーフバイトの16進文字(0-9A-F)を得る.
|
static char |
halfByteCharSmall(int i_)
ハーフバイトの16進文字(0-9a-f)を得る.
|
static byte[] |
parseGraphHex(String graphHex_)
図形16進数(0~9,:~?)
|
static byte[] |
parseGraphHex(String graphHex_,
byte[] buf_,
int offset_,
int len_)
図形16進数(0~9,:~?)
|
static int |
parseHex(String hexStr_,
byte[] buf_,
int offset_,
int len_)
16進文字列をバイナリにしてbyte配列にセットする(試験中).
|
static String |
str(byte n_)
byteを16進文字列で表す(符号無し).
|
static String |
str(byte[] buf_)
バイト配列を16進文字列で表す.
|
static String |
str(byte[] buf_,
int len_)
バイト配列を16進文字列で表す.
|
static String |
str(byte[] buf_,
int offset_,
int length_)
バイト配列を16進文字列で表す.
|
static String |
str(byte[] buf_,
int offset_,
int length_,
String frmt_)
バイト配列をフォーマットされた16進文字列で表す.
|
static String |
str(byte[] buf_,
int len_,
String frmt_)
バイト配列をフォーマットされた16進文字列で表す.
|
static String |
str(byte[] buf_,
String frmt_)
バイト配列をフォーマットされた16進文字列で表す.
|
static String |
str(char n_)
charを16進文字列で表す(符号無し).
|
static String |
str(int n_)
intを16進文字列で表す(符号無し).
|
static String |
str(long n_)
longを16進文字列で表す(符号無し).
|
static String |
str(short n_)
shortを16進文字列で表す(符号無し).
|
static String |
str(String str_)
文字列内部コードを16進数で現す.
|
static String |
str(String text_,
String charSet_)
文字列を16進コードで現す.
|
static String |
str2(int n_)
int(2byte) を4桁の16進数にする
|
static String |
str4(int n_)
int(4byte) を8桁の16進数にする
|
static String |
str1(int n_)
int(1byte) を2桁の16進数にする
|
static byte[] |
toBytes(String hexStr_)
16進文字列からbyte配列を得る.
|
static byte[] |
toBytes(String hexStr_,
long option_)
16進文字列からbyte配列を得る.
|
static String |
toGraphHex(byte[] data_)
バイト配列を0~9,,:~?
|
static String |
toGraphHex(byte[] data_,
int offset_,
int len_)
バイト配列を0~9,,:~?
|
static StringBuilder |
toGraphHex(byte[] data_,
int offset_,
int len_,
StringBuilder sb_)
バイト配列を0~9,:~?
|
static int |
toInt(String hexStr_)
16進文字列をパーズしintをえます。
|
static int |
toInt(String hexStr_,
int OPTION_)
16進文字列をパーズしintをえます。
|
public static int HEX_MAX_LEN
-1をセットすると制限は無しになります。
public static final char[] hexChars
public static final char[] hexCharsSmall
public static final String[] hexByteStrs
public static final String[] hexByteStrsSmall
public static final String[] graphHexByteStrs
public static char halfByteChar(int i_)
i_
- 数値(下位4bitのみ有効)public static char halfByteCharSmall(int i_)
i_
- 数値(下位4bitのみ有効)public static String byteStr(int i_)
i_
- 数値(下位8bitのみ有効)public static String byteStrSmall(int i_)
i_
- 数値(下位8bitのみ有効)public static String str(int n_)
A-Fは大文字となります。
n_
- 値public static String str(short n_)
A-Fは大文字となります。
n_
- 値public static String str(long n_)
n_
- 値public static String str(byte n_)
n_
- 値public static String str(char n_)
n_
- 値public static String str2(int n_)
n_
- 数値public static String str1(int n_)
n_
- 数値public static String str4(int n_)
n_
- 数値public static String str(byte[] buf_)
16進文字列は隙間なく作られます。10~15にはA~Fが当てられます。
例えば10F31A225Fといった形です。
最大バイト長は1024です。最大長を指定したい場合は
str(byte[],int)
を使ってください。
値を4桁で分けたいだとか、a-fを使いたいなど、細かな表示法を
適用させたい場合はstr(byte[],String)
を使います。
buf_
- byte配列public static String str(byte[] buf_, int len_)
16進文字列は隙間なく作られます。10~15にはA~Fが当てられます。
例えば10F31A225Fといった形です。
値を4桁で分けたいだとか、a-fを使いたいなど、細かな表示法を
適用させたい場合はstr(byte[],String)
を使います。
buf_
- byte配列len_
- 表示する最大長public static String str(byte[] buf_, int offset_, int length_)
16進文字列は隙間なく作られます。10~15にはA~Fが当てられます。
例えば10F31A225Fといった形です。
値を4桁で分けたいだとか、a-fを使いたいなど、細かな表示法を
適用させたい場合はstr(byte[],int,int,String)
を使います。
長さがバイト指定であることに注意!
buf_
- バイト配列offset_
- 配列内の有効byteデータ先頭位置length_
- 有効byte長public static String str(byte[] buf_, int offset_, int length_, String frmt_)
単純なフォーマット化を行った16進文字列を得ることができます。
フォーマットは4bitを表すXまたはxとデリミッターーを並べた文字列で
与えます。
'X'を指定すると0-9A-F、'x'を指定すると0-9a-fで表示されます。
フォーマット文字列は先頭から順に繰り返し適用されます。
例えば"%XX"とすると1バイトずつに%が付加された形になります。
"xxxx "とすると2バイトの後に空白がある形が繰り返されます。
Aまたはaを指定すると指定桁数分のアドレスが表示されます。
hiHex.str(data,0x38,8,"%XX"); // %0A%5C%29%80%EF%7D%6B%68 hiHex.str(data,0x38,8,"xxxx "); // 0a5c 2980 ef7d 6b68 hiHex.str(data,0x38,8,"xxxx xxxx / "); // 0a5c 2980 / ef7d 6b68 hiHex.str(data,0x38,8,"AAAA: xxxx xxxx\n"); // 0038: 0a5c 2980 // 003C: ef7d 6b68 hiHex.str(data,0x38,8,"aa:xx "); // 38:0a 39:5c 3a:29 3b:80 ....
buf_
- バイト配列offset_
- 配列内の有効byteデータ先頭位置length_
- 有効byte長frmt_
- フォーマットpublic static String str(byte[] buf_, String frmt_)
フォーマット指定法はstr(byte[],int,int,String)
を参照してください
buf_
- バイト列frmt_
- フォーマットpublic static String str(byte[] buf_, int len_, String frmt_)
フォーマット指定法はstr(byte[],int,int,String)
を参照してください
buf_
- バイト列len_
- 表示するバイト列データ長frmt_
- フォーマットpublic static String toGraphHex(byte[] data_)
data_
- バイト列public static String toGraphHex(byte[] data_, int offset_, int len_)
data_
- バイト列offset_
- データ先頭位置len_
- データ長public static StringBuilder toGraphHex(byte[] data_, int offset_, int len_, StringBuilder sb_)
data_
- バイト列offset_
- 開始位置len_
- 表示するバイト列データ長sb_
- StringBuilderpublic static byte[] parseGraphHex(String graphHex_)
graphHex_
- 図形16進数public static byte[] parseGraphHex(String graphHex_, byte[] buf_, int offset_, int len_)
graphHex_
- 図形16進数buf_
- バイト配列offset_
- 先頭位置len_
- 長さpublic static String str(String text_, String charSet_)
文字列の内部コードを16進表示します。(1文字2バイト4hex)
引数のcharSet_にnullまたは""を指定すると、内部コードが得られます。
text_
- 文字列charSet_
- 文字コードセットpublic static byte[] toBytes(String hexStr_, long option_)
空白文字と'#'は無視されます。
a-f,A-Fどちらも受け付けます。
String str = "01A8C012"; byte[] bytes= hiHex.toBytes(str); // 次の値が得られる // { 0x01,0xA8,0xC0,0x12 }
hexStr_
- 16進文字列option_
- hiU.WITH_EXCEPTIONが指定されると、16進数以外の文字で例外(hiExcception)を発行しますpublic static byte[] toBytes(String hexStr_)
空白文字と'#'は無視されます。
a-f,A-Fどちらも受け付けます。
String str = "01A8C012"; byte[] bytes= hiHex.toBytes(str); // 次の値が得られる // { 0x01,0xA8,0xC0,0x12 }
hexStr_
- 16進文字列public static byte[] base64toBytes(String base64_)
次の作業と同等です
byte[] _data=Base64.getDecoder().decode(base64_);
base64_
- base文字列public static String bytesToBase64(byte[] data_)
次の作業と同等です
String base64Text= Base64.getEncoder().encodeToString(data_);
data_
- バイト列public static int toInt(String hexStr_)
次の操作と同等です。
(int)Long.parseLong(hexStr_,16);
hiHex.toInt("FFFFFFFF")は-1となります。
hexStr_
- 16進文字列 ("0x"無し)public static int toInt(String hexStr_, int OPTION_)
空白は無視されます。
hiHex.toInt("FFFF FFFF",hiU.IGNORE_SPACE)は-1となります。
hexStr_
- 16進文字列 ("0x"無し)OPTION_
- hiU.IGNORE_SPACEうぃpublic static String str(String str_)
文字列の内部コードを16進表示します。(1文字2バイト4hex)
String#getBytes()で得られるものではなく、実際にcharとして保持している
コードです。
str_
- 文字列public static int encodeHex(String hexStr_, byte[] buf_, int offset_, int len_)
parseHex(String,byte[],int,int)
と同じですhexStr_
- 16進文字列buf_
- byte配列offset_
- オフセットlen_
- 無視public static int parseHex(String hexStr_, byte[] buf_, int offset_, int len_)
hexStr_
- 16進文字列buf_
- 値をセットするbyte配列offset_
- 値をセットするbyte配列内位置len_
- 値をセットする配列内長さ