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.
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.
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..
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With