Pre-Lecture Prep and Pre-Quiz
Please read the Bitwise Operators section before class and complete the pre-quiz.
Announcements
- Homework 3 is due today.
- Homework 4 is due next Tuesday at 11:40am EDT.
- Two+ weeks until the midterm:
- there will be a review session Tuesday 10/13 with the midterm Thursday 10/15
- we will go over more details in the next few classes
- A short note on asking questions and help sessions
- Office hours and wizard sessions:
- Delano: Wednesdays at 3pm-5pm EDT (same zoom link as lecture), or by appointment
- Cheever: check his schedule
- Ruether: by appointment Wednesdays 10am-12pm, Thursdays 3pm-5pm EDT (link)
- Wizard sessions: Sunday 1-3pm EDT, Monday 7-9pm EDT (zoom link on moodle)
Learning Objectives and Outcomes
In this lecture, you will...
- read about the fundamentals of bitwise operators
- listen to a short lecture on using bitwise operators to perform different operations on bits (bitwise manipulation)
By the end of this lecture, you should be able to...
- use bitwise manipulation to set, clear, toggle, or test a bit, both on paper and programmatically
Bitwise Operators
In class so far we have discussed logical operators: logical AND (&&
), logical OR (||
), and logical NOT (!
) and comparison operators (e.g. less than <
, equal to (==
)). These logical and comparison operators use the entire variable: 7 < 5
compares 7 and 5 and returns false
. Bitwise operators are similar to logical operators, but function on individual bits. Let's illustrate this by an example:
$\ \ \ 010$
$\& 011$
———
$\ \ \ 010$
In this case, an AND is performed for each bit individually. 0 AND 1 is 0, 1 AND 1 is 1, and 0 AND 0 is 0.
Bitwise operators have the following symbols: