using bash: write bit representation of integer to file
Posted
by theseion
on Stack Overflow
See other posts from Stack Overflow
or by theseion
Published on 2010-04-30T18:18:12Z
Indexed on
2010/04/30
20:17 UTC
Read the original article
Hit count: 339
Hullo
First, I want to use bash for this and the script should run on as many systems as possible (I don't know if the target system will have python or whatever installed).
Here's the problem: I have a file with binary data and I need to replace a few bytes in a certain position. I've come up with the following to direct bash to the offset and show me that it found the place I want:
dd bs=1 if=file iseek=24 conv=block cbs=2 | hexdump
Now, to use "file" as the output:
echo anInteger | dd bs=1 of=hextest.txt oseek=24 conv=block cbs=2
This seems to work just fine, I can review the changes made in a hex editor. Problem is, "anInteger" will be written as the ASCII representation of that integer (which makes sense) but I need to write the binary representation.
How do I tell the command to convert the input to binary (possibly from a hex)?
© Stack Overflow or respective owner