16進数を指定してテストファイル作成・16進数のダンプリスト


フォーマット転送や外字といったHULFTのテストファイルを作成することがあります。
バイナリエディタを使用すれば容易ですが、バイナリエディタ使用禁止の状況も考えられます。
その場合の対処方法をご紹介します。

Windows向け 16進数指定でファイル作成

(コマンド例)
C:\>powershell                              ‥‥‥‥‥1)
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\> [byte[]] $test_data = 0x41 , 0x42 , 0x43             ‥‥‥‥‥2)
PS C:\> Set-Content "C:\temp\ABC.bin" -Value $test_data -Encoding Byte    ‥‥‥3)


1) powershellを実行します。
2) 0xをつけ、カンマ区切りで任意の16進数を指定します。
3) 出力先ファイル名をダブルクォーテーションで囲み指定します。



Windows向け 16進数ダンプリスト

(コマンド例)
C:\>powershell                              ‥‥‥‥‥1)
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\> Format-Hex -Path "C:\temp\ABC.bin"               ‥‥‥‥‥2)



      Path: C:\temp\ABC.bin

      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000 41 42 43                       ABC

1) powershellを実行します。
2) 16進数ダンプを出力したいファイル名をダブルクォーテーションで囲み指定します。


Linux向け 16進数指定でファイル作成

(コマンド例)
$ echo -en "\x41\x42\x43" > /tmp/ABC.bin                ‥‥‥‥‥1)

1) \xをつけた任意の16進数をダブルクォーテーションで囲います。
 また、末尾に出力先ファイル名を指定します。


Linux向け 16進数ダンプリスト

(コマンド例)
$ xxd /tmp/ABC.bin                            ‥‥‥‥‥1)
0000000: 4142 43

1) 出力先ファイル名を末尾に指定します。







お問合せ