I got this code somewhere from the internet
final int time = 80 << 3 + 1;
<<
is a left shift operator
The signed left shift operator "<<" shifts a bit pattern to the left, and the signed right shift operator ">>" shifts a bit pattern to the right. The bit pattern is given by the left-hand operand, and the number of positions to shift by the right-hand operand.
So 24 << 8
means shift binary value of 24 towards left by 8 bits position.
Follow reference to learn more about it.
24 << 8
means shifting the number 24
to the left for 8 bits, which is equivalent to 24 * (2^8) = 6144
.
In the provided code snippet, it encodes a time hh:mm
into an integer hh << 8 + mm
.
Since there are 24 hours in one day, the array to represent the activity of every minute in one day requires (24 << 8) + 1
elements. The +1
is to make the array index for 24:00
legal.