11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

58 Part I: Introduction to C++ Programmingand row 0.) The only combination that returns anything other than 0 is 1 & 1.(This is known as a truth table.)Similarly, the truth table for the OR operator is shown in Table 4-4.Table 4-4Truth Table for the OR OperatorXOR 1 01 1 10 1 0One other logical operation that is not so commonly used in day-to-day livingis the OR ELSE operator commonly contracted to XOR. XOR is true if eitherargument is true but not if both are true. The truth table for XOR is shownin Table 4-5.Table 4-5Truth Table for the XOR OperatorXOR 1 01 0 10 1 0Armed with these single bit operators, we can take on the C++ bitwise logicaloperations.Using the bitwise operatorsThe bitwise operators operate on each bit separately.The bitwise operators are used much like any other binary arithmetic operator.The NOT operator is the easiest to understand. To NOT a number is to NOTeach bit that makes up that number (and to a programmer, that sentencemakes perfect sense — honest). Consider this example:~0110 2 (0x6)1001 2 (0x9)Thus we say that ~0x6 equals 0x9.The following calculation demonstrates the & operator:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!