这是做什么的:"输入>> 4&0x0F"?

Pse*_*che 4 c++ bitwise-operators

我不明白这段代码到底在做什么,有人可以解释一下吗?

long input;  //just here to show the type, assume it has a value stored
unsigned int output( input >> 4 & 0x0F );
Run Code Online (Sandbox Code Playgroud)

谢谢

Mat*_*hew 14

将输入4位向右移位,然后通过低4位进行屏蔽.

以16位数为例:(这些点仅用于视觉分离)

1001.1111.1101.1001 >> 4 = 0000.1001.1111.1101

0000.1001.1111.1101 & 0x0F = 1101 (or 0000.0000.0000.1101 to be more explicit)
Run Code Online (Sandbox Code Playgroud)