Transcript CHAPTER 2

CHAPTER 11

Bit Operations

A Bit

• The Smallest Unit of Information • Has Binomial Representation Such As 1, 0; Yes, No; Black, White; Etc.

• Machine Language • Used to Control the Machine At the Lowest Level • Eight Bits Form A Byte • Data Type

Char

Is Representation of Byte

Bit (Bitwise) Operators

• Operators That Allow Users To Work On Individual Bits • Can be Used To Set, Clear, Test, And Perform Other Operations On Bits • Six Bit Operators Including: & (Bitwise AND),

|

(Bitwise OR)

, ^

(Bitwise Exclusive OR)

, ~

(Complement),

<<

(Shift Left),

>>

(Shift Right)

The And Operator &

• Used To Compare 2 Bits If Both Are 1, the Result Is 1 • Similar To the Logical AND && • Can be Used To Determine A Number Even Or Odd

• Bitwise OR

|: -

Also Known As Inclusive OR operator (OR operator) - If At Least One Bit Is A 1, the Result Is • Bitewise Exlcusive OR

^:

- Known As XOR4 Steps of Programming - If Either Of Its Two Operands Is A 1, But Not Both, the Result Is 1 • Complement Operator

~

(NOT Operator): - Also Called the Inverted Operator or Bit Flip - Inverse Its Operand

• Left And Right Shift Operator

<<, >>:

- Moves Data Left/Right A Specified Number of Bits - Making Bits That Shifted Out Disappear