472,328 Members | 1,776 Online

# 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 1934
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.

Thanks,

Valentina

--
Karthik.
------------ And now a word from our sponsor ---------------------
For a secure high performance FTP using SSL/TLS encryption
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:" |