If I perform a Bitwise AND between a 8 bit integer (int8_t) and 32 bit integer (int) will the result be a 8 bit integer or a 32 bit integer?
I am using GNU/Linux and GCC compiler
To put the question slightly differently, before performing the bitwise AND, are the first 24 bits of the 32 bit integer discarded, or is the 8 bit integer first typecast to a 32 bit integer ?
EDIT: In this little code
#include <iostream>
#include <stdint.h>
int main()
{
int i=34;
int8_t j=2;
std::cout<<sizeof((i&j))<<std::endl;//Bitwise and between a 32 bit integer and 8 bit integer
return 0;
}
I get the output as 4. I would assume that means that the result is a 32 bit integer then. But I don’t know if the result depends on the machine, compiler or OS.
For the
&operator (and most other operators), any operands smaller thanintwill be promoted tointbefore the operation is evaluated.From the C99 standard (6.5.10 – describing the bitwise AND operator):
(6.3.1.8 – describing the usual arithmetic conversions):
(6.3.1.1 – describing the integer promotions):