Modify bit in binary file

Hi,

I'm looking for a simple solution to my problem. I want do modify a single bit into a large binary file. The offset of this bit is known and constant.

For example:

a.bin 		----> 	Operation 	----> 	b.bin
0x100: XXXXXX0 	----> 	Operation 	---->	0x100: XXXXXX1

Because I'm writing a tutorial for beginners this thing should be very easy and no download (scripts, etc) should be done. Is there any possibility to do this?

Thank you all!

Greets,
jodel

Please elaborate on the nature of the modification. Will the case always be as in your example, lowest order bit, which is guaranteed to be zero, toggled to 1 (essentially, just adding 1 to the byte's value)? Or, is the solution required to work on other bits in a byte? And, if the byte is already 1, should it be left unchanged, or should it be toggled to zero? I assume, regardless, that unlike addition, there should be no carry over into higher order bits?

First of all, the goal is to create a second file that differs only in this byte from the original one. The process is only done once.

It would be nice, if the original mask of the byte would not be changed, but at this time this is not a must have. "X" should be don't cares, but assume that they are zeros.

I've found a solution to overwrite a certain byte in a file via dd:

cp a.bin b.bin
dd of=b.bin bs=1 skip=0x100 seek=0x100 count=1 conv=notrunc 

Is there any possibilty to echo non-printable characters via there ascii-code (I need 0x01)? Sorry, I'm new to shell using..

It seems that the BSD-Version of echo doesn't have the '-e' switch..

printf '\x01'

If you intend to feed the output of printf to dd, you'll probably want to drop the 'skip' option.

Regards,
Alister

You're right. It finally works, yeah!

Final version:

cp a.bin b.bin
printf "\x01" | dd of=b.bin bs=1 seek=0x100 count=1 conv=notrunc
cmp -b -c a.bin b.bin

Thank you, alister! Please close!