# ITP 165 Lecture 25: Bitwise Operators

36 views2 pages
ITP 165: Intro to C++ - Lecture 25: Bitwise Operators
Bitwise Operators
β Bitwise operators operate on each bit of binary number(s) in a specific way
β We will cover 4 different bitwise operators in C++:
β ~ bitwise NOT
β & bitwise AND
β | bitwise OR
β ^ bitwise XOR
β Bitwise NOT operates on a single number, whereas AND, OR, XOR operate between
two numbers
Bitwise NOT
β Bitwise NOT flips every bit in a single binary number
β So something that was previously a 0 will instead be a 1, and viceversa
Bitwise AND
β In a bitwise AND, you line up the binary digits of two numbers
β Any places that are a 1 in both numbers are a 1 in the result
Bitwise OR
β In a bitwise OR, you line up the binary digits of two numbers
β Any places that are a 1 in either of the numbers are a 1 in the result
Bitwise XOR
β In a bitwise XOR (exclusive or), you line up the binary digits of two numbers
β Any places that are a 1 in one but only one of the numbers are a 1 in the result
Usages
β Bit-flips
β Determining unknown bits
β Encryption/Decryption
β Graphics
Bit Shifts
β Bit shift operation moves the sequence to the left or right
β Many types of bit shifts
β Focus on Arithmetic Shifts
Bit Shift Left
β 8 th bit (in the 7 spot) is shifted out, all bits shifted LEFT, 0 shifted in to make 8 bits (in
the 0 spot)
β b = a << 1; (left shift)
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

## Document Summary

Itp 165: intro to c++ - lecture 25: bitwise operators. Bitwise operators operate on each bit of binary number(s) in a specific way. We will cover 4 different bitwise operators in c++: Bitwise not operates on a single number, whereas and, or, xor operate between two numbers. Bitwise not flips every bit in a single binary number. So something that was previously a 0 will instead be a 1, and viceversa. In a bitwise and, you line up the binary digits of two numbers. Any places that are a 1 in both numbers are a 1 in the result. In a bitwise or, you line up the binary digits of two numbers. Any places that are a 1 in either of the numbers are a 1 in the result. In a bitwise xor (exclusive or), you line up the binary digits of two numbers.

## Get access

\$8 USD/m\$10 USD/m
Billed \$96 USD annually
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class