Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to use the bitwise logical operators in programs ❏ To be able to use.

Similar presentations


Presentation on theme: "Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to use the bitwise logical operators in programs ❏ To be able to use."— Presentation transcript:

1 Computer Science: A Structured Programming Approach Using C1 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 Chapter 14 Chapter 14 Bitwise Operators Bitwise Operators

2 Computer Science: A Structured Programming Approach Using C2 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.

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

4 Computer Science: A Structured Programming Approach Using C4 14-2 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. Bitwise and Operator Bitwise Inclusive or Operator Bitwise Exclusive or Operator One’s Complement Operator Topics discussed in this section:

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

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

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

8 Computer Science: A Structured Programming Approach Using C8 Table 14-3Inclusive Or Truth Table

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

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

11 Computer Science: A Structured Programming Approach Using C11 Table 14-4Exclusive Or Truth Table

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

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

14 Computer Science: A Structured Programming Approach Using C14 Table 14-5One’s Complement Truth Table

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

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

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

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

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

20 Computer Science: A Structured Programming Approach Using C20 14-3 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. Shift Rotation Topics discussed in this section:

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

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

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

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

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

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

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

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

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

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

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

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

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


Download ppt "Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to use the bitwise logical operators in programs ❏ To be able to use."

Similar presentations


Ads by Google