Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing the first 16 bytes from a byte array

Tags:

java

bytearray

In Java, how do I take a byte[] array and remove the first 16 bytes from the array? I know I might have to do this by copying the array into a new array. Any examples or help would be appreciated.

like image 593
Icemanind Avatar asked Sep 20 '11 03:09

Icemanind


People also ask

How many bits is a byte array?

A byte consists of 8 bits. Each byte can store a decimal value up to 255 or 11111111 in binary form. Using these properties, we can develop a function that takes an integer input and converts the number into a specific byte array that represents the integer in binary form.

What is a byte array?

A byte array is simply an area of memory containing a group of contiguous (side by side) bytes, such that it makes sense to talk about them in order: the first byte, the second byte etc..

How do you find the byte of an array?

To determine the size of your array in bytes, you can use the sizeof operator: int a[17]; size_t n = sizeof(a); On my computer, ints are 4 bytes long, so n is 68.


1 Answers

See Arrays class in the Java library:

Arrays.copyOfRange(byte[] original, int from, int to)

from is inclusive, whereas to is exclusive. Both are zero based indices, so to remove the first 16 bytes do

Arrays.copyOfRange(original, 16, original.length);
like image 105
Jim Garrison Avatar answered Sep 26 '22 14:09

Jim Garrison