If you have long text or text in a file, you can also use the binmake tool, which allows you to describe some binary data in text format and generate a binary file (or output to stdout). This allows you to change the endianess and number formats and accept comments.
The default format is hexadecimal, but not limited to this.
First get and compile binmake :
$ git clone https://github.com/dadadel/binmake $ cd binmake $ make
You can use it with stdin and stdout :
$ echo '32 decimal 32 61 %x20 %x61' | ./binmake | hexdump -C 00000000 32 20 3d 20 61 |2 = a| 00000005
Or use files. So create your text file file.txt :
# an exemple of file description of binary data to generate # set endianess to big-endian big-endian # default number is hexadecimal 00112233 # man can explicit a number type: %b means binary number %b0100110111100000 # change endianess to little-endian little-endian # if no explicit, use default 44556677 # bytes are not concerned by endianess 88 99 aa bb # change default to decimal decimal # following number is now decimal 0123 # strings are delimited by " or ' "this is some raw string" # explicit hexa number starts with %x %xff
Create your binary file.bin file:
$ ./binmake file.txt file.bin $ hexdump file.bin -C 00000000 00 11 22 33 4d e0 77 66 55 44 88 99 aa bb 7b 74 |.."3M.wfUD....{t| 00000010 68 69 73 20 69 73 20 73 6f 6d 65 20 72 61 77 20 |his is some raw | 00000020 73 74 72 69 6e 67 ff |string.| 00000027
daouzli
source share