1

Delete 64 bytes every 2048 bytes in binary

 2 years ago
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

advertisements

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:

  1. While you haven't reached the EOF of STDIN,
    1. Read 2112 bytes from STDIN
    2. From the bytes read, remove the 64 bytes starting at position 1536.
    3. 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?

Is it possible to delete N bytes from begining of a file in C? N is 30 bytes only. I can't copy a file because they are very large (sometimes even 100 of GBs)On Linux you can create a loopback device pointing to an offset within another file. Here is

How to decompress 4 bytes of binary data in 3 bytes and 1 byte?

I have 4 bytes of binary data (big-endian) that I want to unpack. If it contained two 2-byte unsigned integer values, this would be straightforward: a, b = data.unpack("C>C>") But what if the data contains a 3-byte value (a) followed by a

Read 40 bytes of binary data as ascii text

I have some binary data, in hex editor it looks like: s.o.m.e.d.a.t.a with all these dots in between each letter when I read with filehandle.read(40) it shows these dots I know that the dots aren't supposed to be there, is there a way to unpack some

How do I convert bytes to binary string in python?

I have some numbers that represent bytes, and I want to make a binary string of those. By binary string, I mean b"something" Here's my attempt, for the record of "making some research". I tried to google it, but found only the other di

Need to convert a byte array / binary UDP DatagramPacket to multiple fields in java

I have a byte array that consists of a 10 byte message. I know the first 2 bytes contains an id that would like to extract out to a string. An example of this id is: 2001. The remaining bytes consist of other fields which I am aware. I am receiving t

Convert byte to binary in Java

I am trying to convert a byte value to binary for data transfer. Basically, I am sending a value like "AC" in binary ("10101100") in a byte array where "10101100" is a single byte. I want to be able to receive this byte and c

How do I convert PID in Erlang in 1 byte to binary?

I need to convert pid to binary in Erlang, and send it to another pid. But i need the size of the binary data to be 1 byte. Is it posible?You can't do this. One byte can only represent 256 different values, and there are more than 256 possible proces

How to convert a byte to binary representation in int in java

I have a String[] with byte values String[] s = {"110","101","100","11","10","1","0"}; Looping through s, I want to get int values out of it. I am currently using this Byte b = new Byte

Javascript array of bytes in binary string?

This is my array of bytes: var $x = [108,181,183,176,140,239,53,105,104,47,47,21,147,67,96,87,175,35,67,97] It has a binary PHP equivalent of gibberish: $x = "lµ·°Œï5ih//"C``W¯#Ca"; Now, what I can use so that javascript:btoa(SOME_ENCODING_

Java - bytes and binary

This is a basic question. When I use a byte stream to write bytes to a file, am I creating a binary file? For example: I use a byte stream to write text data to a notepad and when I open the notepad in a HEX viewer I see the corresponding hex value f

How to change the order of bytes of binary data

I have a binary file which I'm reading where some 2 byte values are stored in 'reverse' byte order (little endian?), eg. 1D 00 13 00 27 00 3B 00 45 00 31 00 4F The original program that created these values stores them internally as shorts. Those val

Byte to Binary String C # - Show 8 digits

I want to display one byte in textbox. Now I'm using: Convert.ToString(MyVeryOwnByte, 2); But when byte is has 0's at begining those 0's are being cuted. Example: MyVeryOwnByte = 00001110 // Texbox shows -> 1110 MyVeryOwnByte = 01010101 // Texbox sho

How to delete X bytes from the end of a large file without reading the entire file?

In Linux, I have a rather large file with some extraneous information tacked on to the end of it. Let's say for example I know there are 314 bytes of extraneous data at the end of a 1.6GB file. Of course it is very easy and efficient to add more data

how to read 10000 bytes [] of binary data from DataBase?

I have one table that contains Company's Logo.... whenever I read small image like 4096 bytes It works perfectly, but i am not able to read over the 10000 bytes in php. it's read only 4096 bytes from database Update: Column Lenth in Sql : My Code in

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK