SlideShare a Scribd company logo
1 of 18
By
Y N D ARAVIND
Associate Professor, Dept Of CSE
Newton’s Group Of Institutions, Macherla
@2020 Presented By Mr.Y N D Aravind 1
Part- I
Exact Size Integer Types
Logical Bitwise Operators
Shift Operators
@2020 Presented By Mr.Y N D Aravind 2
Exact Size Integer Types
 The integer can be of two types – Unsigned integers and
signed integers.
 They can be of four types –short int, int, long int, long
long int.
 As integer is one of the datatype it is built in so it is
machine dependent.
 The size of int may be 4 bytes on computer and on
another it is 2 bytes.
 In other applications we need to fix the size of integers.
 C allows us to define integer types of sizes 8 bits, 16 bits,
32 bits and 64 bits.
 They are defined in stdint.h header file.
Presented By Mr.Y N D Aravind
3
Exact Size Integer Types
Presented By Mr.Y N D Aravind 4
Bitwise operators are used for manipulation of data at bit level.
Operator Meaning
& Bitwise AND.
| Bitwise OR.
^ Bitwise Exclusive OR.
<< Shift left.
>> shift right.
~ One’s complement.
These bits are used to test the bits, or shifting them right to left.
These operators may not be applied to float or double.
These operators are works on integers and characters.
Presented By Mr.Y N D Aravind
5
Bits are numbered from zero onwards increasing
order from right to left.
15 14 13 12 11 10 9 8 7 6
5 4 3 2 1 0
16-bit integer
7 6 5 4 3 2 1 0
8- bit integer
Presented By Mr.Y N D Aravind
6
The truth table for Bitwise AND is
A B A & B
0 0 0
0 1 0
1 0 0
1 1 1
Program:- Write a program to use bitwise AND operator between two integer.
Source code:-
#include <stdio.h>
main()
{
int a,b;
printf(“n Enter a, b values”);
scanf(“%d %d”,&a,&b);
printf(“n After bitwise AND is %d ”,a&b);
}
Presented By Mr.Y N D Aravind
7
Enter a, b values 3 2
After bitwise AND is 2
To perform Bitwise AND operator:-
a=3
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
b=2
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
a & b
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
a & b =2
Presented By Mr.Y N D Aravind
8
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
The truth table for Bitwise OR is
A B A | B
0 0 0
0 1 1
1 0 1
1 1 1
Program:- Write a program to use bitwise OR operator between two integer.
Source code:-
#include <stdio.h>
main()
{
int a,b;
printf(“n Enter a, b values”);
scanf(“%d %d”,&a,&b);
printf(“n After bitwise OR is %d”,a|b);
}
Presented By Mr.Y N D Aravind
9
Enter a, b values 3 2
After bitwise OR is 3
To perform Bitwise OR operator:-
a=3
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
b=2
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
a | b
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
a | b =3
Presented By Mr.Y N D Aravind
10
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
The truth table for Bitwise EXCLUSIVE OR is
A B A ^ B
0 0 0
0 1 1
1 0 1
1 1 0
Program:- Write a program to use bitwise Exclusive OR operator between two
integer.
Source code:-
#include <stdio.h>
main()
{
int a,b;
printf(“n Enter a, b values”);
scanf(“%d %d”,&a,&b);
printf(“n After bitwise ECLUSIVE OR is %d”,a ^ b);
}
Presented By Mr.Y N D Aravind
11
Enter a, b values 3 2
After bitwise Exclusive OR is 1
To perform Bitwise Exclusive OR operator:-
a=3
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
b=2
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
a ^ b
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
a ^ b =1
Presented By Mr.Y N D Aravind
12
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
The one‟s complement operator is a unary operator that
requires one operand only. It complements the bits in the
operand. That means it finds the reverse of the operand bit.
The result of the operand is 1 if the original bit is 0 and it is 0
if the original bit is 1. The truth table for one‟s complement
operator is shown below:
Presented By Mr.Y N D Aravind
13
Write a program to shift inputted data by two bits right..
Source code:-
#include <stdio.h>
main()
{
int x,y;
printf(“n Enter x value”);
scanf(“%d”,&x);
x>>=2;
y=x;
printf(“n The right shifted data is =%d”,y);
} Presented By Mr.Y N D Aravind
14
Enter x value 8
The right shifted data is = 2
To perform Right shift operator:-
x=8
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Right shift 2 bits
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
y = 2
Presented By Mr.Y N D Aravind
15
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
Write a program to shift inputted data by three bits left.
Source code:-
#include <stdio.h>
main()
{
int x,y;
printf(“n Enter x value”);
scanf(“%d”,&x);
X<<=3;
y=x;
printf(“n The left shifted data is =%d”,y);
}
Presented By Mr.Y N D Aravind
16
Enter x value 2
The left shifted data is = 16
To perform Left shift operator:-
x=2
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Right shift 2 bits
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
y = 16
Presented By Mr.Y N D Aravind
17
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
Presented By Mr.Y N D Aravind
18

More Related Content

What's hot

J - K & MASTERSLAVE FLIPFLOPS
J - K & MASTERSLAVE FLIPFLOPSJ - K & MASTERSLAVE FLIPFLOPS
J - K & MASTERSLAVE FLIPFLOPSKrishma Parekh
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
C Pointers
C PointersC Pointers
C Pointersomukhtar
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 
Ripple counter
Ripple counterRipple counter
Ripple counterchandkec
 
Passing an Array to a Function (ICT Programming)
Passing an Array to a Function (ICT Programming)Passing an Array to a Function (ICT Programming)
Passing an Array to a Function (ICT Programming)Fatima Kate Tanay
 
Nested structure (Computer programming and utilization)
Nested structure (Computer programming and utilization)Nested structure (Computer programming and utilization)
Nested structure (Computer programming and utilization)Digvijaysinh Gohil
 
pseudo code basics
pseudo code basicspseudo code basics
pseudo code basicsSabik T S
 
Floating point presentation
Floating point presentationFloating point presentation
Floating point presentationSnehalataAgasti
 
Call by value
Call by valueCall by value
Call by valueDharani G
 
Types of function call
Types of function callTypes of function call
Types of function callArijitDhali
 
Digital Electronics- Number systems & codes
Digital Electronics- Number systems & codes Digital Electronics- Number systems & codes
Digital Electronics- Number systems & codes VandanaPagar1
 

What's hot (20)

BCD.
BCD.BCD.
BCD.
 
J - K & MASTERSLAVE FLIPFLOPS
J - K & MASTERSLAVE FLIPFLOPSJ - K & MASTERSLAVE FLIPFLOPS
J - K & MASTERSLAVE FLIPFLOPS
 
Structure in C
Structure in CStructure in C
Structure in C
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
 
C Pointers
C PointersC Pointers
C Pointers
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Ripple counter
Ripple counterRipple counter
Ripple counter
 
Passing an Array to a Function (ICT Programming)
Passing an Array to a Function (ICT Programming)Passing an Array to a Function (ICT Programming)
Passing an Array to a Function (ICT Programming)
 
Nested structure (Computer programming and utilization)
Nested structure (Computer programming and utilization)Nested structure (Computer programming and utilization)
Nested structure (Computer programming and utilization)
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Counters
CountersCounters
Counters
 
Unit 4-booth algorithm
Unit 4-booth algorithmUnit 4-booth algorithm
Unit 4-booth algorithm
 
pseudo code basics
pseudo code basicspseudo code basics
pseudo code basics
 
Floating point presentation
Floating point presentationFloating point presentation
Floating point presentation
 
Call by value
Call by valueCall by value
Call by value
 
Types of function call
Types of function callTypes of function call
Types of function call
 
Digital Electronics- Number systems & codes
Digital Electronics- Number systems & codes Digital Electronics- Number systems & codes
Digital Electronics- Number systems & codes
 

Similar to Bitwise Operators in C

C Programming Language
C Programming LanguageC Programming Language
C Programming LanguageRTS Tech
 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2Zaibi Gondal
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans incnayakq
 
Lesson 11. Pattern 3. Shift operations
Lesson 11. Pattern 3. Shift operationsLesson 11. Pattern 3. Shift operations
Lesson 11. Pattern 3. Shift operationsPVS-Studio
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programsPrasadu Peddi
 
Lab 10 sem ii_12_13
Lab 10 sem ii_12_13Lab 10 sem ii_12_13
Lab 10 sem ii_12_13alish sha
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in cSaranya saran
 
GSP 215 RANK Education Your Life--gsp215rank.com
GSP 215 RANK Education Your Life--gsp215rank.comGSP 215 RANK Education Your Life--gsp215rank.com
GSP 215 RANK Education Your Life--gsp215rank.comthomashard64
 
GSP 215 RANK Inspiring Innovation--gsp215rank.com
GSP 215 RANK Inspiring Innovation--gsp215rank.com GSP 215 RANK Inspiring Innovation--gsp215rank.com
GSP 215 RANK Inspiring Innovation--gsp215rank.com KeatonJennings102
 
GSP 215 RANK Lessons in Excellence-- gsp215rank.com
GSP 215 RANK Lessons in Excellence-- gsp215rank.comGSP 215 RANK Lessons in Excellence-- gsp215rank.com
GSP 215 RANK Lessons in Excellence-- gsp215rank.comRoelofMerwe102
 
GSP 215 Enhance teaching/tutorialrank.com
 GSP 215 Enhance teaching/tutorialrank.com GSP 215 Enhance teaching/tutorialrank.com
GSP 215 Enhance teaching/tutorialrank.comjonhson300
 
GSP 215 Inspiring Innovation/tutorialrank.com
GSP 215 Inspiring Innovation/tutorialrank.comGSP 215 Inspiring Innovation/tutorialrank.com
GSP 215 Inspiring Innovation/tutorialrank.comjonhson129
 
GSP 215 RANK Become Exceptional--gsp215rank.com
GSP 215 RANK Become Exceptional--gsp215rank.comGSP 215 RANK Become Exceptional--gsp215rank.com
GSP 215 RANK Become Exceptional--gsp215rank.comclaric119
 
GSP 215 RANK Achievement Education--gsp215rank.com
GSP 215 RANK Achievement Education--gsp215rank.comGSP 215 RANK Achievement Education--gsp215rank.com
GSP 215 RANK Achievement Education--gsp215rank.comclaric169
 
C Programming Language Part 4
C Programming Language Part 4C Programming Language Part 4
C Programming Language Part 4Rumman Ansari
 

Similar to Bitwise Operators in C (20)

C Programming Language
C Programming LanguageC Programming Language
C Programming Language
 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
 
Interesting facts on c
Interesting facts on cInteresting facts on c
Interesting facts on c
 
operators.ppt
operators.pptoperators.ppt
operators.ppt
 
Lesson 11. Pattern 3. Shift operations
Lesson 11. Pattern 3. Shift operationsLesson 11. Pattern 3. Shift operations
Lesson 11. Pattern 3. Shift operations
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 
C important questions
C important questionsC important questions
C important questions
 
Lab 10 sem ii_12_13
Lab 10 sem ii_12_13Lab 10 sem ii_12_13
Lab 10 sem ii_12_13
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
 
GSP 215 RANK Education Your Life--gsp215rank.com
GSP 215 RANK Education Your Life--gsp215rank.comGSP 215 RANK Education Your Life--gsp215rank.com
GSP 215 RANK Education Your Life--gsp215rank.com
 
GSP 215 RANK Inspiring Innovation--gsp215rank.com
GSP 215 RANK Inspiring Innovation--gsp215rank.com GSP 215 RANK Inspiring Innovation--gsp215rank.com
GSP 215 RANK Inspiring Innovation--gsp215rank.com
 
GSP 215 RANK Lessons in Excellence-- gsp215rank.com
GSP 215 RANK Lessons in Excellence-- gsp215rank.comGSP 215 RANK Lessons in Excellence-- gsp215rank.com
GSP 215 RANK Lessons in Excellence-- gsp215rank.com
 
GSP 215 Enhance teaching/tutorialrank.com
 GSP 215 Enhance teaching/tutorialrank.com GSP 215 Enhance teaching/tutorialrank.com
GSP 215 Enhance teaching/tutorialrank.com
 
GSP 215 Inspiring Innovation/tutorialrank.com
GSP 215 Inspiring Innovation/tutorialrank.comGSP 215 Inspiring Innovation/tutorialrank.com
GSP 215 Inspiring Innovation/tutorialrank.com
 
Operators
OperatorsOperators
Operators
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 
GSP 215 RANK Become Exceptional--gsp215rank.com
GSP 215 RANK Become Exceptional--gsp215rank.comGSP 215 RANK Become Exceptional--gsp215rank.com
GSP 215 RANK Become Exceptional--gsp215rank.com
 
GSP 215 RANK Achievement Education--gsp215rank.com
GSP 215 RANK Achievement Education--gsp215rank.comGSP 215 RANK Achievement Education--gsp215rank.com
GSP 215 RANK Achievement Education--gsp215rank.com
 
C Programming Language Part 4
C Programming Language Part 4C Programming Language Part 4
C Programming Language Part 4
 

More from yndaravind

Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UMLyndaravind
 
Classes and Objects
Classes and Objects  Classes and Objects
Classes and Objects yndaravind
 
The Object Model
The Object Model  The Object Model
The Object Model yndaravind
 
Repetations in C
Repetations in CRepetations in C
Repetations in Cyndaravind
 
Selection & Making Decisions in c
Selection & Making Decisions in cSelection & Making Decisions in c
Selection & Making Decisions in cyndaravind
 
Structure In C
Structure In CStructure In C
Structure In Cyndaravind
 
Fnctions part2
Fnctions part2Fnctions part2
Fnctions part2yndaravind
 
Functions part1
Functions part1Functions part1
Functions part1yndaravind
 

More from yndaravind (14)

Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 
Classes and Objects
Classes and Objects  Classes and Objects
Classes and Objects
 
The Object Model
The Object Model  The Object Model
The Object Model
 
OOAD
OOADOOAD
OOAD
 
OOAD
OOADOOAD
OOAD
 
FILES IN C
FILES IN CFILES IN C
FILES IN C
 
Repetations in C
Repetations in CRepetations in C
Repetations in C
 
Selection & Making Decisions in c
Selection & Making Decisions in cSelection & Making Decisions in c
Selection & Making Decisions in c
 
Structure In C
Structure In CStructure In C
Structure In C
 
Strings part2
Strings part2Strings part2
Strings part2
 
Arrays In C
Arrays In CArrays In C
Arrays In C
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
Fnctions part2
Fnctions part2Fnctions part2
Fnctions part2
 
Functions part1
Functions part1Functions part1
Functions part1
 

Recently uploaded

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 

Bitwise Operators in C

  • 1. By Y N D ARAVIND Associate Professor, Dept Of CSE Newton’s Group Of Institutions, Macherla @2020 Presented By Mr.Y N D Aravind 1
  • 2. Part- I Exact Size Integer Types Logical Bitwise Operators Shift Operators @2020 Presented By Mr.Y N D Aravind 2
  • 3. Exact Size Integer Types  The integer can be of two types – Unsigned integers and signed integers.  They can be of four types –short int, int, long int, long long int.  As integer is one of the datatype it is built in so it is machine dependent.  The size of int may be 4 bytes on computer and on another it is 2 bytes.  In other applications we need to fix the size of integers.  C allows us to define integer types of sizes 8 bits, 16 bits, 32 bits and 64 bits.  They are defined in stdint.h header file. Presented By Mr.Y N D Aravind 3
  • 4. Exact Size Integer Types Presented By Mr.Y N D Aravind 4
  • 5. Bitwise operators are used for manipulation of data at bit level. Operator Meaning & Bitwise AND. | Bitwise OR. ^ Bitwise Exclusive OR. << Shift left. >> shift right. ~ One’s complement. These bits are used to test the bits, or shifting them right to left. These operators may not be applied to float or double. These operators are works on integers and characters. Presented By Mr.Y N D Aravind 5
  • 6. Bits are numbered from zero onwards increasing order from right to left. 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 16-bit integer 7 6 5 4 3 2 1 0 8- bit integer Presented By Mr.Y N D Aravind 6
  • 7. The truth table for Bitwise AND is A B A & B 0 0 0 0 1 0 1 0 0 1 1 1 Program:- Write a program to use bitwise AND operator between two integer. Source code:- #include <stdio.h> main() { int a,b; printf(“n Enter a, b values”); scanf(“%d %d”,&a,&b); printf(“n After bitwise AND is %d ”,a&b); } Presented By Mr.Y N D Aravind 7
  • 8. Enter a, b values 3 2 After bitwise AND is 2 To perform Bitwise AND operator:- a=3 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 b=2 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 a & b 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 a & b =2 Presented By Mr.Y N D Aravind 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
  • 9. The truth table for Bitwise OR is A B A | B 0 0 0 0 1 1 1 0 1 1 1 1 Program:- Write a program to use bitwise OR operator between two integer. Source code:- #include <stdio.h> main() { int a,b; printf(“n Enter a, b values”); scanf(“%d %d”,&a,&b); printf(“n After bitwise OR is %d”,a|b); } Presented By Mr.Y N D Aravind 9
  • 10. Enter a, b values 3 2 After bitwise OR is 3 To perform Bitwise OR operator:- a=3 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 b=2 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 a | b 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 a | b =3 Presented By Mr.Y N D Aravind 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
  • 11. The truth table for Bitwise EXCLUSIVE OR is A B A ^ B 0 0 0 0 1 1 1 0 1 1 1 0 Program:- Write a program to use bitwise Exclusive OR operator between two integer. Source code:- #include <stdio.h> main() { int a,b; printf(“n Enter a, b values”); scanf(“%d %d”,&a,&b); printf(“n After bitwise ECLUSIVE OR is %d”,a ^ b); } Presented By Mr.Y N D Aravind 11
  • 12. Enter a, b values 3 2 After bitwise Exclusive OR is 1 To perform Bitwise Exclusive OR operator:- a=3 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 b=2 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 a ^ b 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 a ^ b =1 Presented By Mr.Y N D Aravind 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
  • 13. The one‟s complement operator is a unary operator that requires one operand only. It complements the bits in the operand. That means it finds the reverse of the operand bit. The result of the operand is 1 if the original bit is 0 and it is 0 if the original bit is 1. The truth table for one‟s complement operator is shown below: Presented By Mr.Y N D Aravind 13
  • 14. Write a program to shift inputted data by two bits right.. Source code:- #include <stdio.h> main() { int x,y; printf(“n Enter x value”); scanf(“%d”,&x); x>>=2; y=x; printf(“n The right shifted data is =%d”,y); } Presented By Mr.Y N D Aravind 14
  • 15. Enter x value 8 The right shifted data is = 2 To perform Right shift operator:- x=8 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Right shift 2 bits 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 y = 2 Presented By Mr.Y N D Aravind 15 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
  • 16. Write a program to shift inputted data by three bits left. Source code:- #include <stdio.h> main() { int x,y; printf(“n Enter x value”); scanf(“%d”,&x); X<<=3; y=x; printf(“n The left shifted data is =%d”,y); } Presented By Mr.Y N D Aravind 16
  • 17. Enter x value 2 The left shifted data is = 16 To perform Left shift operator:- x=2 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Right shift 2 bits 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 y = 16 Presented By Mr.Y N D Aravind 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
  • 18. Presented By Mr.Y N D Aravind 18