Delete 64 bytes every 2048 bytes in binary
source link: https://www.codesd.com/item/delete-64-bytes-every-2048-bytes-in-binary.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Delete 64 bytes every 2048 bytes in binary
I'm at a loose end here, it seems like such a simple problem so I'm hoping there is a simple answer!
I have a binary (approx 35m) which has 64 bytes of padded data every 2048 bytes starting at offset 1536 - I just want to remove this padding.
The first occurrence is 1536, then 3648,5760,7872,etc
(2112 bytes - 64 bytes of dummy data = 2048)
I've tried bvi,bbe,hexdump+sed+xxd and I'm clearly missing something.
Thanks in advance,
You didn't show any code, so I presume you need help wrapping your head around the algorithm. It's actually quite simple:
- While you haven't reached the EOF of STDIN,
- Read 2112 bytes from STDIN
- From the bytes read, remove the 64 bytes starting at position 1536.
- Print the remaining 2048 bytes to STDOUT.
In Perl,
binmode(STDIN);
binmode(STDOUT);
while (1) {
my $rv = read(STDIN, my $rec, 2112);
die $! if !defined($rv);
last if !$rv;
substr($rec, 1536, 64, '');
print($rec)
or die $!;
}
Related Articles
Is it possible to delete N bytes from the beginning of a file in C?
How to decompress 4 bytes of binary data in 3 bytes and 1 byte?
Read 40 bytes of binary data as ascii text
How do I convert bytes to binary string in python?
Need to convert a byte array / binary UDP DatagramPacket to multiple fields in java
Convert byte to binary in Java
How do I convert PID in Erlang in 1 byte to binary?
How to convert a byte to binary representation in int in java
Javascript array of bytes in binary string?
Java - bytes and binary
How to change the order of bytes of binary data
Byte to Binary String C # - Show 8 digits
How to delete X bytes from the end of a large file without reading the entire file?
how to read 10000 bytes [] of binary data from DataBase?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK