In Java << there is a logical left shift. 0 is always added as LSB.
(Note that Java will advance the specified value [byte], so care should be taken to mask back to octect! Otherwise, you will save the shifted bit (s), which could include "1".)
However, the Wikipedia article on Arithmetic Shift indicates that arithmetic left shift can lead to an overflow error:
... Please note that arithmetic left shift can cause overflow; this is the only way that differs from a logical left shift.
(This is not the case in Java, but just need to be kept in mind.)
Happy coding.
user166390
source share