关于c中的 移位操作,谁解释一下?
大家好:
我看了一篇文章 :http://www.codeproject.com/cpp/bitbashing.asp
他解释了 移位操作,其中有几个地方不明白。
1.An ideal use for this is to set up a mask to check the values of certain bits. Say we have a BYTE that contains some bit flags, and we want to check if bit four bit is set.
BYTE b = 50;
if ( b & 0x10 )
cout << "Bit four is set" << endl;
else
cout << "Bit four is clear" << endl;
请问这样0,1做了比较后有什麽好处,他是希望得到什麽效果呢?
2.四位的bit代表0~F十五个数字,四个bit用nibble来表示,它可以把bit和十六进制联系起来:
So if we had one BYTE containing the letter 'r' (ASCII code 114) it would look like this:
0111 0010 binary
7 2 hexadecimal
请问这样联系有什麽好处,为哪里带来了方便呢?据个例子好吗?
多谢!