Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trim few bytes of a byte array?

I have a long byte array. I need to eliminate the initial 16 bytes. Is there a shortcut do it?

like image 958
NewBie Avatar asked Sep 22 '11 08:09

NewBie


People also ask

Can we compress byte array?

Compressing a byte array is a matter of recognizing repeating patterns within a byte sequence and devising a method that can represent the same underlying information to take advantage of these discovered repetitions.

What is byte array size?

The bytearray class is a mutable sequence of integers in the range of 0 to 256.

What is byte and byte array?

bytes is an immutable version of bytearray – it has the same non-mutating methods and the same indexing and slicing behavior. Syntax: bytes([source[, encoding[, errors]]]) bytearray() function : Return a new array of bytes. The bytearray type is a mutable sequence of integers in the range 0 <= x < 256.

What is the maximum size of byte array?

Max Size It generally depends on the JVM that we're using and the platform. Since the index of the array is int, the approximate index value can be 2^31 – 1. Based on this approximation, we can say that the array can theoretically hold 2,147,483,647 elements.


2 Answers

This is not the most efficient thing, but will do the trick:

// using System.Linq;

long[] array = ...;

long[] newArray = array.Skip(16).ToArray();
like image 148
Steven Avatar answered Oct 21 '22 21:10

Steven


Check out Array.Copy
For example:

var array = //initialization
int bytesToEliminate = 16;
int newLength = array.Length - bytesToEliminate; //you may need to check if this positive
var newArray = new byte[newLength]; 
Array.Copy(array, bytesToEliminate, newArray, 0, newLength);
like image 7
default locale Avatar answered Oct 21 '22 19:10

default locale