I am trying to figure out how to remove leading zeros from an array. The array is currently stored with the least significant bit at the first position.
Example: if number is 1101 it is stored in my array as: [1,1,0,1]. I do not want to flip the array or change it in anyway except remove the leading zeros. I have the bolded the leading zero that needs to be removed.
I am trying to just do this with just using the array and not converting it
Ex: current output : 0 1 1 0
Expected output: 0 1 1
public static byte[] normal(byte[] arr)
{
//check if all the numbers are 0 and last is 1
byte [] output = new byte[copy.length];
for(int i = arr.length;i<=0;i--)
{
if(arr[i]==1){
output[i]=copy[i];
}
}
return output;
}