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}
0

2 Answers 2

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).

Sign up to request clarification or add additional context in comments.

Comments

0

With Linq you can do this:

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.