0

How can I subtracts bytes from array to make a new set of bytes. For Example below I need to subtract the first 4 bytes and make new array with remaining bytes of 0x45, 0x54, 0x47.

What do I need to do in order to make new array of bytes from the existing array of bytes by removing the first 4 set of bytes.

public static byte[] somebyte = { 0x4f, 0x46, 0x46, 0x53, 0x45, 0x54, 0x47}

what I need

public static byte[] somenewbyte = {0x45, 0x54, 0x47}
O.GHOST
  • 1
  • 1

2 Answers2

2

You can use Linq

var somenewbyte = somebyte.Skip(4).ToArray();

You can also use Array.Copy. You have to pre-allocate somenewbyte with the correct size. However, you may find Array.Copy to be more CPU efficient on a large array (you won't measure the difference on a small array like this).

Eric J.
  • 147,927
  • 63
  • 340
  • 553
0

With Linq you can do this:

var somenewbyte = somebyte.Skip(4).ToArray()
AlexDrenea
  • 7,981
  • 1
  • 32
  • 49