What does this line mean?

V

Valentina

What does this C++ line mean?

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

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

Valentina
 
K

Karthik Kumar

Valentina said:
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 ----
 
P

Pedro Graca

Valentina said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top