What do you think the following program will print?
https://gist.github.com/09755207f9bdfd13f71639d3e0f301cd
This program will print: 4
.
When you use iota
in a const
group, the values of the constants will advance according to the first operation. The <<
operator is "left shift". It moves the bits of a number to the left, basically multiplying it by power of 2.
For example, if we have the number 5, which (on byte, which is 8 bits) is 00000101
. When you write 5 << 1
all the bits are shifted one place to the left. Making it 00001010
which is 10=5*2
. When you write 5 << 2
the bits are shifted two places to the left, making it 00010100
or 20=5*4
.