How to write binary values into a file in Bash instead of ASCII values
7
votes
2
answers
2435
views
I am dealing with an embedded system which has some memory that is accessible by a file descriptor (I have no idea what am I saying, so please correct me if I am wrong).
This memory is 32 kB and I want to fill it with 0x00 to 0xFFFFFFFF. I know this for text files:
exec {fh} >> ./eeprom;
for i in {0..32767}; do echo $i >& $fh; done; $fh>&-;
This will write ASCII characters 0 to 977.
And if I do a
hexdump eeprop | head
I get:
0000000 0a30 0a31 0a32 0a33 0a34 0a35 0a36 0a37
0000010 0a38 0a39 3031 310a 0a31 3231 310a 0a33
0000020 3431 310a 0a35 3631 310a 0a37 3831 310a
0000030 0a39 3032 320a 0a31 3232 320a 0a33 3432
0000040 320a 0a35 3632 320a 0a37 3832 320a 0a39
0000050 3033 330a 0a31 3233 330a 0a33 3433 330a
0000060 0a35 3633 330a 0a37 3833 330a 0a39 3034
0000070 340a 0a31 3234 340a 0a33 3434 340a 0a35
0000080 3634 340a 0a37 3834 340a 0a39 3035 350a
0000090 0a31 3235 350a 0a33 3435 350a 0a35 3635
How can I fill each address with its uint32
, not the ASCII representation?
Asked by DEKKER
(998 rep)
Aug 5, 2022, 08:56 AM
Last activity: Aug 8, 2022, 06:26 AM
Last activity: Aug 8, 2022, 06:26 AM