I am trying to add two values in a byte array. This is my code:
byte[] ars = {3,6,9,2,4}; ars[0] = (byte)ars[0] + (byte)ars[4]; System.out.println( ars[0] );
close, but a little off.
ars[0] = (byte)(ars[0] + ars[4]);
keep in mind ars[0] and ars[4] are already bytes, so there is no need to cast them to bytes.
ars[0]
ars[4]
Instead, cast the result of the summation to a byte.