05.05.2014 Views

csmstr - Omega Engineering

csmstr - Omega Engineering

csmstr - Omega Engineering

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

WRITING EXPRESSIONS<br />

MANIPULATING BITS<br />

MANIPULATING BITS<br />

Crimson also provides operators to perform operations that do not treat integers as numeric<br />

values, but instead as sequences of bits. These operators are known as bitwise operators.<br />

AND, OR AND XOR<br />

These three bitwise operators each produce a result in which each bit is defined to be equal to<br />

the corresponding bits in the values on the operator’s left-hand and right-hand sides,<br />

combined using a specific truth-table…<br />

OPERATOR PRIORITY EXAMPLE<br />

Bitwise AND Group 8 Data & Mask<br />

Bitwise OR Group 9 Data | Mask<br />

Bitwise XOR Group 10 Data ^ Mask<br />

The table below shows the associated truth tables…<br />

A B A & B A | B A ^ B<br />

0 0 0 0 0<br />

0 1 0 1 1<br />

1 0 0 1 1<br />

1 1 1 1 0<br />

SHIFT OPERATORS<br />

Crimson also provides operators to shift an integer n bits to the left or right…<br />

OPERATOR PRIORITY EXAMPLE<br />

Shift Left Group 5 Data > 2<br />

Each example shifts Data two bits in the specified direction.<br />

BITWISE NOT<br />

Finally, Crimson provides a bitwise NOT operator to invert the sense of the bits in a value…<br />

OPERATOR PRIORITY EXAMPLE<br />

Bitwise NOT Group 2 ~Mask<br />

This example produces a value where every bit is equal to the opposite of its value in Mask.<br />

REVISION 6 PAGE 265

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

Saved successfully!

Ooh no, something went wrong!