SlideShare a Scribd company logo
1 of 33
Computer Science: A Structured Programming Approach Using C 1
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
Bitwise Operators
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
Table 14-1 Fixed-size Integer Types
Computer Science: A Structured Programming Approach Using C 4
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:
Computer Science: A Structured Programming Approach Using C 5
Table 14-2 And Truth Table
Computer Science: A Structured Programming Approach Using C 6
PROGRAM 14-1 Simple Bitwise And Demonstration
Computer Science: A Structured Programming Approach Using C 7
PROGRAM 14-1 Simple Bitwise And Demonstration
Computer Science: A Structured Programming Approach Using C 8
Table 14-3 Inclusive Or Truth Table
Computer Science: A Structured Programming Approach Using C 9
PROGRAM 14-2 Simple Inclusive or Demonstration
Computer Science: A Structured Programming Approach Using C 10
PROGRAM 14-2 Simple Inclusive or Demonstration
Computer Science: A Structured Programming Approach Using C 11
Table 14-4 Exclusive Or Truth Table
Computer Science: A Structured Programming Approach Using C 12
PROGRAM 14-3 Simple Exclusive or Demonstration
Computer Science: A Structured Programming Approach Using C 13
PROGRAM 14-3 Simple Exclusive or Demonstration
Computer Science: A Structured Programming Approach Using C 14
Table 14-5 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
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:
Computer Science: A Structured Programming Approach Using C 21
FIGURE 14-2 Shift-right Operation
Computer Science: A Structured Programming Approach Using C 22
PROGRAM 14-6 Simple Shift-right Demonstration
Computer Science: A Structured Programming Approach Using C 23
PROGRAM 14-6 Simple Shift-right Demonstration
Computer Science: A Structured Programming Approach Using C 24
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
PROGRAM 14-7 Simple Shift-left Demonstration
Computer Science: A Structured Programming Approach Using C 28
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
PROGRAM 14-8 Rotate Left and Right Test Driver
Computer Science: A Structured Programming Approach Using C 32
PROGRAM 14-8 Rotate Left and Right Test Driver
Computer Science: A Structured Programming Approach Using C 33
PROGRAM 14-8 Rotate Left and Right Test Driver

More Related Content

Similar to Chap-14-1 (1).ppt

Similar to Chap-14-1 (1).ppt (20)

C programming-1.pptx
C programming-1.pptxC programming-1.pptx
C programming-1.pptx
 
Chap 01-1 jwfiles
Chap 01-1 jwfilesChap 01-1 jwfiles
Chap 01-1 jwfiles
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Sample Programs.ppt
Sample Programs.pptSample Programs.ppt
Sample Programs.ppt
 
test(3)arithmetic in c
test(3)arithmetic in ctest(3)arithmetic in c
test(3)arithmetic in c
 
Variable-intro.pptx
Variable-intro.pptxVariable-intro.pptx
Variable-intro.pptx
 
Chap-08-4.ppt
Chap-08-4.pptChap-08-4.ppt
Chap-08-4.ppt
 
Chap-07-1.ppt
Chap-07-1.pptChap-07-1.ppt
Chap-07-1.ppt
 
Chap-03-1.ppt
Chap-03-1.pptChap-03-1.ppt
Chap-03-1.ppt
 
UoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfUoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdf
 
Intro
IntroIntro
Intro
 
Computer graphics 9068
Computer graphics  9068Computer graphics  9068
Computer graphics 9068
 
C programs
C programsC programs
C programs
 
Lesson 2 beginning the problem solving process
Lesson 2 beginning the problem solving processLesson 2 beginning the problem solving process
Lesson 2 beginning the problem solving process
 
CG_U1_M1_PPT_1.pptx
CG_U1_M1_PPT_1.pptxCG_U1_M1_PPT_1.pptx
CG_U1_M1_PPT_1.pptx
 
Chapter 01 Planning Computer Program (re-upload)
Chapter 01 Planning Computer Program (re-upload)Chapter 01 Planning Computer Program (re-upload)
Chapter 01 Planning Computer Program (re-upload)
 
Chapter 11 pcp
Chapter 11 pcpChapter 11 pcp
Chapter 11 pcp
 
Fy secondsemester2016
Fy secondsemester2016Fy secondsemester2016
Fy secondsemester2016
 
Fy secondsemester2016
Fy secondsemester2016Fy secondsemester2016
Fy secondsemester2016
 
Fy secondsemester2016
Fy secondsemester2016Fy secondsemester2016
Fy secondsemester2016
 

Recently uploaded

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 

Recently uploaded (20)

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 

Chap-14-1 (1).ppt

  • 1. Computer Science: A Structured Programming Approach Using C 1 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 Bitwise Operators
  • 2. 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.
  • 3. Computer Science: A Structured Programming Approach Using C 3 Table 14-1 Fixed-size Integer Types
  • 4. Computer Science: A Structured Programming Approach Using C 4 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 C 5 Table 14-2 And Truth Table
  • 6. Computer Science: A Structured Programming Approach Using C 6 PROGRAM 14-1 Simple Bitwise And Demonstration
  • 7. Computer Science: A Structured Programming Approach Using C 7 PROGRAM 14-1 Simple Bitwise And Demonstration
  • 8. Computer Science: A Structured Programming Approach Using C 8 Table 14-3 Inclusive Or Truth Table
  • 9. Computer Science: A Structured Programming Approach Using C 9 PROGRAM 14-2 Simple Inclusive or Demonstration
  • 10. Computer Science: A Structured Programming Approach Using C 10 PROGRAM 14-2 Simple Inclusive or Demonstration
  • 11. Computer Science: A Structured Programming Approach Using C 11 Table 14-4 Exclusive Or Truth Table
  • 12. Computer Science: A Structured Programming Approach Using C 12 PROGRAM 14-3 Simple Exclusive or Demonstration
  • 13. Computer Science: A Structured Programming Approach Using C 13 PROGRAM 14-3 Simple Exclusive or Demonstration
  • 14. Computer Science: A Structured Programming Approach Using C 14 Table 14-5 One’s Complement Truth Table
  • 15. Computer Science: A Structured Programming Approach Using C 15 PROGRAM 14-4 One’s Complement
  • 16. Computer Science: A Structured Programming Approach Using C 16 PROGRAM 14-4 One’s Complement
  • 17. Computer Science: A Structured Programming Approach Using C 17 FIGURE 14-1 Checksum Calculation
  • 18. Computer Science: A Structured Programming Approach Using C 18 PROGRAM 14-5 Demonstrate Checksum
  • 19. Computer Science: A Structured Programming Approach Using C 19 PROGRAM 14-5 Demonstrate Checksum
  • 20. Computer Science: A Structured Programming Approach Using C 20 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 C 21 FIGURE 14-2 Shift-right Operation
  • 22. Computer Science: A Structured Programming Approach Using C 22 PROGRAM 14-6 Simple Shift-right Demonstration
  • 23. Computer Science: A Structured Programming Approach Using C 23 PROGRAM 14-6 Simple Shift-right Demonstration
  • 24. Computer Science: A Structured Programming Approach Using C 24 PROGRAM 14-6 Simple Shift-right Demonstration
  • 25. Computer Science: A Structured Programming Approach Using C 25 Table 14-6 Divide by Shift
  • 26. Computer Science: A Structured Programming Approach Using C 26 FIGURE 14-3 Shift-left Operation
  • 27. Computer Science: A Structured Programming Approach Using C 27 PROGRAM 14-7 Simple Shift-left Demonstration
  • 28. Computer Science: A Structured Programming Approach Using C 28 PROGRAM 14-7 Simple Shift-left Demonstration
  • 29. Computer Science: A Structured Programming Approach Using C 29 Table 14-7 Multiply by Shift
  • 30. Computer Science: A Structured Programming Approach Using C 30 FIGURE 14-4 Right and Left Rotation
  • 31. Computer Science: A Structured Programming Approach Using C 31 PROGRAM 14-8 Rotate Left and Right Test Driver
  • 32. Computer Science: A Structured Programming Approach Using C 32 PROGRAM 14-8 Rotate Left and Right Test Driver
  • 33. Computer Science: A Structured Programming Approach Using C 33 PROGRAM 14-8 Rotate Left and Right Test Driver