469,898 Members | 1,408 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

What does this line mean?

What does this C++ line mean?

bool bBoolean = (0!=(nInteger&0x08));

I don't understand the nInteger&0x08 bit.
Thanks,

Valentina
Jul 22 '05 #1
2 1837
Valentina wrote:
What does this C++ line mean?

bool bBoolean = (0!=(nInteger&0x08));

bBoolean is true, if nInteger's 4th LSB is set.
' bool bBoolean = ( 0 != (nInteger & 0x08)); '

spacing surely helps sometimes to understand code beter.

I don't understand the nInteger&0x08 bit.

Google for 'bitwise operators' .

Thanks,

Valentina

--
Karthik.
------------ And now a word from our sponsor ---------------------
For a secure high performance FTP using SSL/TLS encryption
upgrade to SurgeFTP
---- See http://netwinsite.com/sponsor/sponsor_surgeftp.htm ----
Jul 22 '05 #2
Valentina wrote:
What does this C++ line mean?

bool bBoolean = (0!=(nInteger&0x08));
// I like to separate operands and operators
bool bBoolean = (0 != (nInteger & 0x08));
I don't understand the nInteger&0x08 bit.


'&' is the bitwise AND operator


// 00010111 = 23 in binary | 00011000 = 24 in binary
// & 00001000 = 8 in binary | & 00001000 = 8 in binary
// ---------- | ----------
// 00000000 = 23 & 8 ( == 0 ) | 00001000 = 24 & 8 ( != 0 )
that line is testing nInteger's fourth bit from the left;
if it's 0 bBoolean will be false, if it's 1 bBoolean will be true.
HTH
--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

47 posts views Thread by Neal | last post: by
72 posts views Thread by E. Robert Tisdale | last post: by
121 posts views Thread by typingcat | last post: by
1 post views Thread by vishal | last post: by
6 posts views Thread by Seven Kast USA | last post: by
13 posts views Thread by Jason Huang | last post: by
92 posts views Thread by Heinrich Pumpernickel | last post: by
3 posts views Thread by qianz99 | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.