Simple logic behind C++ statement

Hello World,

Can any of you explain how this statement works--ie: the logic behind this statement--especially the underlined part(the part before the conditional statement, but after the assignment operator):
cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ;

**Note**
----------------------------------------------------------------------------------
I have some knowledge about fonts and the conditional operator.
----------------------------------------------------------------------------------

Thanks,
Aceix.
Last edited on
closed account (zb0S216C)
See here: http://msdn.microsoft.com/en-us/library/z0zec0b2(v=vs.71).aspx

Wazzak
tm.tmPitchAndFamily & 1

This is a bitwise AND operator on the variables 1 and tm.tmPitchAndFamily. This gives a value of 1 if the lowest bit of tm.tmPitchAndFamily is 1, and zero otherwise.

?
This checks the result of the previous operation. If it is non-zero, then 3. If it is zero, then 2.

(tm.tmPitchAndFamily & 1 ? 3 : 2)
So this will produce 3 if the lowest bit of tm.tmPitchAndFamily is 1, and will produce 2 otherwise.
Last edited on
Thank you all for the help.

Aceix.
Topic archived. No new replies allowed.