关于c中的 移位操作,谁解释一下?

jcreatorqijiashe jcreatorqijiashe 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
大家好:

我看了一篇文章 :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
请问这样联系有什麽好处,为哪里带来了方便呢?据个例子好吗?
多谢!
...全文

相关推荐

评论 11
收藏 已收藏
分享
返回顶部
jcreatorqijiashe
C语言 70,040 成员 243,237 内容