检查位 [英] checking bits
本文介绍了检查位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个字符,我想检查第3位是0还是1 ......
我该怎么做?
谢谢!
lets say i have a char, and i want to check if the 3rd bit is 0 or 1...
how might i do this?
thanks!
推荐答案
" Mark" < MN ******* @ gmail.com>在消息中写道
news:11 ********************** @ g43g2000cwa.googlegr oups.com ...
"Mark" <mn*******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
让我说我有一个字符,我想检查第3位是0还是1 ......
我该怎么做?
lets say i have a char, and i want to check if the 3rd bit is 0 or 1...
how might i do this?
了解按位运算符,
例如| ,&等等
你也应该使用无符号字符。
-Mike
Learn about the bitwise operators,
e.g. | , & , etc.
Also you should used unsigned characters for this.
-Mike
" Mike Wahler" < MK ****** @ mkwahler.net>在消息中写道
news:4e ***************** @ newsread1.news.pas.earthl ink.net ...
"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:4e*****************@newsread1.news.pas.earthl ink.net...
标记 < MN ******* @ gmail.com>在消息中写道
新闻:11 ********************** @ g43g2000cwa.googlegr oups.com ...
"Mark" <mn*******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
假设我有一个字符,我想检查第3位是0还是1 ......
我该怎么做?
lets say i have a char, and i want to check if the 3rd bit is 0 or 1...
how might i do this?
了解按位运算符,
例如| ,&等等
你也应该使用无符号字符。
Learn about the bitwise operators,
e.g. | , & , etc.
Also you should used unsigned characters for this.
另外,还有''std :: bitset' '从标准库中输入
。
-Mike
Alternatively, there''s the ''std::bitset'' type
from the standard library.
-Mike
好的。谢谢:)
这应该可以帮助其他任何关心的人。
http://www.cprogramming.com/tutorial...operators.html
alright. thanks :)
this should help anyone else who cares to know
http://www.cprogramming.com/tutorial...operators.html
这篇关于检查位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文