Upon reading the ASM 4.1 source code I've found instances of the following:
int ASM4 = 4 << 16 | 0 << 8 | 0; int ASM5 = 5 << 16 | 0 << 8 | 0;
Does these left shifts of zero by 8 do anything to the expression, or the 'or' by 0 for that matter?
Wouldn't it be equivalent to just have:
int ASM4 = 4 << 16; int ASM5 = 5 << 16;
The left-shift operator causes the bits in shift-expression to be shifted to the left by the number of positions specified by additive-expression . The bit positions that have been vacated by the shift operation are zero-filled.
The left shift operator ( << ) shifts the first operand the specified number of bits, modulo 32, to the left. Excess bits shifted off to the left are discarded. Zero bits are shifted in from the right.
The number to the left of the operator is shifted the number of places specified by the number to the right. Each shift to the left doubles the number, therefore each left shift multiplies the original number by 2. Use the left shift for fast multiplication or to pack a group of numbers together into one larger number.
1 in binary is 0001 , then bitshifting it by 0 won't do anything, which aligns with what you observed. So any number x << 0 is equivalent to x * 2^0 , which is x * 1 , which is just x .
Indeed they are equivalent but one possible explanation is that they wanted to map the version numbers including both the major and minor numbers to a unique ID in their code. So in the following:
int ASM4 = 4 << 16 | 0 << 8 | 0; // this looks like 4.0.0 int ASM5 = 5 << 16 | 0 << 8 | 0; // this looks list 5.0.0
The 4
and 5
represent versions 4
and 5
respectively, and the zero
in 0 << 8
could potentially be the minor numbers, and the last zero
is another minor number, as in 4.0.0
and 5.0.0
. But that's my guess anyway. You'd really have to ask the authors.
In context:
// ASM API versions int ASM4 = 4 << 16 | 0 << 8 | 0; int ASM5 = 5 << 16 | 0 << 8 | 0;
Yes, this is equivalent to
int ASM4 = 4 << 16; int ASM5 = 5 << 16;
This is just written that way to make it clear that we are setting the 3rd byte to 4, and both lower bytes to 0. Alternatively, that it is a version number that should be read as 4.0.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With