I want to split a long long
(a 64-bit value) into two int
s (32-bit each). For this I'm using the "standard way" of shifting the long long
right by 32 to get the upper 32-bit and cast the long long
to an int to get the lower 32-bit. However, clang-tidy
reports the shift as warning:
Use of a signed integer operand with a binary bitwise operator
My code is the following:
void split_long_long(long long value, int &upper, int &lower) {
upper = (int) (value >> 32); // <- Warning here at "value"
lower = (int) value;
}
How would you rewrite this to avoid the warning?
Note that writing
void split_long_long(unsigned long long int value, unsigned int &upper, unsigned int &lower) {
upper = (unsigned int) (value >> 32);
lower = (unsigned int) value;
}
does not fix the warning either, even though there are only unsigned
variables in use.