Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 14 Bitwise Operators Objectives

Similar presentations


Presentation on theme: "Chapter 14 Bitwise Operators Objectives"— Presentation transcript:

1 Chapter 14 Bitwise Operators Objectives
❏ To be able to use the bitwise logical operators in programs ❏ To be able to use the bitwise shift operators in programs ❏ To understand how to create and use masks to manipulate bits Computer Science: A Structured Programming Approach Using C

2 14-1 Exact Size Integer Types
The integer types, such as int and long, are machine dependent. In one computer, the size of int may be four bytes; in another computer it may be two bytes. While many bitwise applications work well on machine-dependent integer types, other applications need to assure that the size is fixed. C allows us to define integer types of sizes 8, 16, 32, and 64 bits. Computer Science: A Structured Programming Approach Using C

3 Fixed-size Integer Types
Table 14-1 Fixed-size Integer Types Computer Science: A Structured Programming Approach Using C

4 Topics discussed in this section:
Logical Bitwise Operators The logical operators look at data as individual bits to be manipulated. Four operators are provided to manipulate bits: bitwise and (&), bitwise inclusive or (|), bitwise exclusive or (^), and one’s complement (~). The first three are binary operators; the one’s complement is a unary operator. Topics discussed in this section: Bitwise and Operator Bitwise Inclusive or Operator Bitwise Exclusive or Operator One’s Complement Operator Computer Science: A Structured Programming Approach Using C

5 Table 14-2 And Truth Table Computer Science: A Structured Programming Approach Using C

6 Simple Bitwise And Demonstration
PROGRAM 14-1 Simple Bitwise And Demonstration Computer Science: A Structured Programming Approach Using C

7 Simple Bitwise And Demonstration
PROGRAM 14-1 Simple Bitwise And Demonstration Computer Science: A Structured Programming Approach Using C

8 Inclusive Or Truth Table
Computer Science: A Structured Programming Approach Using C

9 Simple Inclusive or Demonstration
PROGRAM 14-2 Simple Inclusive or Demonstration Computer Science: A Structured Programming Approach Using C

10 Simple Inclusive or Demonstration
PROGRAM 14-2 Simple Inclusive or Demonstration Computer Science: A Structured Programming Approach Using C

11 Exclusive Or Truth Table
Computer Science: A Structured Programming Approach Using C

12 Simple Exclusive or Demonstration
PROGRAM 14-3 Simple Exclusive or Demonstration Computer Science: A Structured Programming Approach Using C

13 Simple Exclusive or Demonstration
PROGRAM 14-3 Simple Exclusive or Demonstration Computer Science: A Structured Programming Approach Using C

14 One’s Complement Truth Table
Computer Science: A Structured Programming Approach Using C

15 PROGRAM 14-4 One’s Complement
Computer Science: A Structured Programming Approach Using C

16 PROGRAM 14-4 One’s Complement
Computer Science: A Structured Programming Approach Using C

17 FIGURE 14-1 Checksum Calculation
Computer Science: A Structured Programming Approach Using C

18 PROGRAM 14-5 Demonstrate Checksum
Computer Science: A Structured Programming Approach Using C

19 PROGRAM 14-5 Demonstrate Checksum
Computer Science: A Structured Programming Approach Using C

20 Topics discussed in this section:
Shift Operators The shift operators move bits to the right or the left. When applied to unsigned numbers, these operators are implementation independent. When used with signed numbers, however, the implementation is left to the discretion of the software engineer who designs the compiler. Topics discussed in this section: Shift Rotation Computer Science: A Structured Programming Approach Using C

21 FIGURE 14-2 Shift-right Operation
Computer Science: A Structured Programming Approach Using C

22 Simple Shift-right Demonstration
PROGRAM 14-6 Simple Shift-right Demonstration Computer Science: A Structured Programming Approach Using C

23 Simple Shift-right Demonstration
PROGRAM 14-6 Simple Shift-right Demonstration Computer Science: A Structured Programming Approach Using C

24 Simple Shift-right Demonstration
PROGRAM 14-6 Simple Shift-right Demonstration Computer Science: A Structured Programming Approach Using C

25 Table 14-6 Divide by Shift Computer Science: A Structured Programming Approach Using C

26 FIGURE 14-3 Shift-left Operation
Computer Science: A Structured Programming Approach Using C

27 Simple Shift-left Demonstration
PROGRAM 14-7 Simple Shift-left Demonstration Computer Science: A Structured Programming Approach Using C

28 Simple Shift-left Demonstration
PROGRAM 14-7 Simple Shift-left Demonstration Computer Science: A Structured Programming Approach Using C

29 Table 14-7 Multiply by Shift
Computer Science: A Structured Programming Approach Using C

30 FIGURE 14-4 Right and Left Rotation
Computer Science: A Structured Programming Approach Using C

31 Rotate Left and Right Test Driver
PROGRAM 14-8 Rotate Left and Right Test Driver Computer Science: A Structured Programming Approach Using C

32 Rotate Left and Right Test Driver
PROGRAM 14-8 Rotate Left and Right Test Driver Computer Science: A Structured Programming Approach Using C

33 Rotate Left and Right Test Driver
PROGRAM 14-8 Rotate Left and Right Test Driver Computer Science: A Structured Programming Approach Using C


Download ppt "Chapter 14 Bitwise Operators Objectives"

Similar presentations


Ads by Google