I am trying to understand shift operators in C/C++, but they are giving me a tough time.
I have an unsigned 8-bit integer initialized to a value, for the example, say 1.
uint8_t x = 1;
From my understanding, it is represented in the memory like |0|0|0|0|0||0||0||1|
. Now, when I am trying to left shit the variable x by 16 bit, I am hoping to get output 0. But to my surprise, I am getting 65536
. I am certainly missing something which I am not able to get.
Here's my code:
#include <iostream>
int main() {
uint8_t x = 1;
std::cout<<(x<<16)<<"\n";
return 0;
}
It's a naive question, but it is bothering me a lot.