SlideShare a Scribd company logo
C Bitwise Operators
Bitwise operators are used to manipulate one or more bits from integral operands like
char, int, short, long, here we will see the basics of bitwise operators, and some useful
tips for manipulating the bits to achieve a task. Bitwise operators operate on
individual bits of integer (int and long) values. This is useful for writing low-level
hardware or OS code where the ordinary abstractions of numbers, characters, pointers,
and so on, are insufficient. Bit manipulation code tends to be less "portable". Code is
"portable" if without any programmer intervention it compiles and runs correctly on
different types of computers. The bit wise operations are commonly used with
unsigned types. These operators perform bit wise logical operations on values. Both
operands must be of the same type and width: the resultant value will also be this type
and width. A bitwise operator works on each bit of data. Bitwise operators are used in
bit level programming the Bitwise operators supported by C language are listed in the
following table.
Assume variable A holds 60 and variable B holds 13 then:
Operator Description Example
&
Binary AND Operator copies a bit to the
result if it exists in both operands.
(A & B) will give 12 which
is 0000 1100
|
Binary OR Operator copies a bit if it exists in
either operand.
(A | B) will give 61 which is
0011 1101
^
Binary XOR Operator copies the bit if it is set
in one operand but not both.
(A ^ B) will give 49 which is
0011 0001
~
Binary Ones Complement Operator is unary
and has the effect of 'flipping' bits.
(~A ) will give -61 which is
1100 0011 in 2's complement
form due to a signed binary
number.
<<
Binary Left Shift Operator. The left operands
value is moved left by the number of bits
specified by the right operand.
A << 2 will give 240 which
is 1111 0000
>>
Binary Right Shift Operator. The left
operands value is moved right by the number
of bits specified by the right operand.
A >> 2 will give 15 which is
0000 1111
Bitwise OR – |
Bitwise OR operator | takes 2 bit patterns, and perform OR operations on each pair of
corresponding bits. The following example will explain it.
1010
1100
--------
OR 1110
--------
The Bitwise OR, will take pair of bits from each position, and if any one of the bit is
1, the result on that position will be 1.
Bitwise AND – &
Bitwise AND operator &, takes 2 bit patterns, and perform AND operations with it.
1010
1100
-------
AND 1000
-------
The Bitwise AND will take pair of bits from each position, and if only both the bit is
1, the result on that position will be 1
One’s Complement operator – ~
One’s complement operator (Bitwise NOT) is used to convert each “1-bit to 0-bit”
and “0-bit to 1-bit”, in the given binary pattern. It is a unary operator i.e. it takes only
one operand.
1001
NOT
-------
0110
-------
Bitwise XOR – ^
Bitwise XOR ^, takes 2 bit patterns and perform XOR operation with it.
0101
0110
------
XOR 0011
------
The Bitwise XOR will take pair of bits from each position, and if both the bits are
different, the result on that position will be 1. If both bits are same, then the result on
that position is 0.
Bit a Bit b a & b a | b a ^ b ~a
0 0 0 0 0 1
0 1 0 1 1 1
1 0 0 1 1 0
1 1 1 1 0 0
#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=3;
printf("%dn",a|b);
printf("%dn",a&b);
printf("%dn",a^b);
getch();
}
Right Shift
a = 0000 0011 = 3
(a<<=1) = 00000110 = 6
(a<<=2) = 00011000 = 24
(a<<=3) = 11000000 = 192
Left Shift
a=11000000 =192
(a>>=1) = 01100000 = 96
(a>>=2) = 00011000 = 24
(a>>=3) = 0000 0011 = 3
a = 12
b = 10
---------------------------------
a in Binary : 0000 0000 0000 1100
b in Binary : 0000 0000 0000 1010
---------------------------------
a | b : 0000 0000 0000 1110
a & b : 0000 0000 0000 1000
a ^ b : 0000 0000 0000 0110
a | b : 0000 0000 0000 1110 = 14
a & b : 0000 0000 0000 1000 = 8
a ^ b : 0000 0000 0000 0110 = 6

More Related Content

What's hot

Von-Neumann machine and IAS architecture
Von-Neumann machine and  IAS architectureVon-Neumann machine and  IAS architecture
Von-Neumann machine and IAS architecture
Shishir Aryal
 
Microoperations
MicrooperationsMicrooperations
Microoperations
Rakesh Pillai
 
Register in Digital Logic
Register in Digital LogicRegister in Digital Logic
Register in Digital Logic
ISMT College
 
Counter
CounterCounter
Counter
Naufal Qodari
 
K map.
K map.K map.
Octal to binary encoder
Octal to binary encoderOctal to binary encoder
Octal to binary encoder
Ajay844
 
simplification of boolean algebra
simplification of boolean algebrasimplification of boolean algebra
simplification of boolean algebra
mayannpolisticoLNU
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
Chamila Fernando
 
Data Representation
Data RepresentationData Representation
Data Representation
Education Front
 
Computer arithmetic
Computer arithmeticComputer arithmetic
Computer arithmetic
Balakrishna Chowdary
 
Binary Arithmetic Operations
Binary Arithmetic OperationsBinary Arithmetic Operations
Binary Arithmetic Operations
Digital System Design
 
K Map Simplification
K Map SimplificationK Map Simplification
K Map Simplification
Ramesh C
 
Digital Electronics - Counters
Digital Electronics - CountersDigital Electronics - Counters
Digital Electronics - Counters
Jayakrishnan J
 
Operators in C/C++
Operators in C/C++Operators in C/C++
Operators in C/C++
Shobi P P
 
BOOLEAN ALGEBRA AND LOGIC GATE
BOOLEAN ALGEBRA AND LOGIC GATE BOOLEAN ALGEBRA AND LOGIC GATE
BOOLEAN ALGEBRA AND LOGIC GATE
Tamim Tanvir
 
Two’s complement
Two’s complementTwo’s complement
Two’s complement
mayannpolisticoLNU
 
Automata theory - CFG and normal forms
Automata theory - CFG and normal formsAutomata theory - CFG and normal forms
Automata theory - CFG and normal forms
Akila Krishnamoorthy
 
Registers
RegistersRegisters
Registers
Sanjeev Patel
 
Scope rules : local and global variables
Scope rules : local and global variablesScope rules : local and global variables
Scope rules : local and global variables
sangrampatil81
 
1d-HALF ADDER & FULL ADDER-PPT.pdf
1d-HALF ADDER & FULL ADDER-PPT.pdf1d-HALF ADDER & FULL ADDER-PPT.pdf
1d-HALF ADDER & FULL ADDER-PPT.pdf
ssusera0b94b
 

What's hot (20)

Von-Neumann machine and IAS architecture
Von-Neumann machine and  IAS architectureVon-Neumann machine and  IAS architecture
Von-Neumann machine and IAS architecture
 
Microoperations
MicrooperationsMicrooperations
Microoperations
 
Register in Digital Logic
Register in Digital LogicRegister in Digital Logic
Register in Digital Logic
 
Counter
CounterCounter
Counter
 
K map.
K map.K map.
K map.
 
Octal to binary encoder
Octal to binary encoderOctal to binary encoder
Octal to binary encoder
 
simplification of boolean algebra
simplification of boolean algebrasimplification of boolean algebra
simplification of boolean algebra
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
Data Representation
Data RepresentationData Representation
Data Representation
 
Computer arithmetic
Computer arithmeticComputer arithmetic
Computer arithmetic
 
Binary Arithmetic Operations
Binary Arithmetic OperationsBinary Arithmetic Operations
Binary Arithmetic Operations
 
K Map Simplification
K Map SimplificationK Map Simplification
K Map Simplification
 
Digital Electronics - Counters
Digital Electronics - CountersDigital Electronics - Counters
Digital Electronics - Counters
 
Operators in C/C++
Operators in C/C++Operators in C/C++
Operators in C/C++
 
BOOLEAN ALGEBRA AND LOGIC GATE
BOOLEAN ALGEBRA AND LOGIC GATE BOOLEAN ALGEBRA AND LOGIC GATE
BOOLEAN ALGEBRA AND LOGIC GATE
 
Two’s complement
Two’s complementTwo’s complement
Two’s complement
 
Automata theory - CFG and normal forms
Automata theory - CFG and normal formsAutomata theory - CFG and normal forms
Automata theory - CFG and normal forms
 
Registers
RegistersRegisters
Registers
 
Scope rules : local and global variables
Scope rules : local and global variablesScope rules : local and global variables
Scope rules : local and global variables
 
1d-HALF ADDER & FULL ADDER-PPT.pdf
1d-HALF ADDER & FULL ADDER-PPT.pdf1d-HALF ADDER & FULL ADDER-PPT.pdf
1d-HALF ADDER & FULL ADDER-PPT.pdf
 

Viewers also liked

Module 00 Bitwise Operators in C
Module 00 Bitwise Operators in CModule 00 Bitwise Operators in C
Module 00 Bitwise Operators in C
Tushar B Kute
 
Operating Systems - Dynamic Memory Management
Operating Systems - Dynamic Memory ManagementOperating Systems - Dynamic Memory Management
Operating Systems - Dynamic Memory Management
Emery Berger
 
Bitwise AND operator in c
Bitwise AND operator in cBitwise AND operator in c
Bitwise AND operator in c
Innovative
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C language
Rakesh Roshan
 
C Prog. - Operators and Expressions
C Prog. - Operators and ExpressionsC Prog. - Operators and Expressions
C Prog. - Operators and Expressionsvinay arora
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 
Deep C
Deep CDeep C
Deep C
Olve Maudal
 

Viewers also liked (8)

logical 8051
logical 8051logical 8051
logical 8051
 
Module 00 Bitwise Operators in C
Module 00 Bitwise Operators in CModule 00 Bitwise Operators in C
Module 00 Bitwise Operators in C
 
Operating Systems - Dynamic Memory Management
Operating Systems - Dynamic Memory ManagementOperating Systems - Dynamic Memory Management
Operating Systems - Dynamic Memory Management
 
Bitwise AND operator in c
Bitwise AND operator in cBitwise AND operator in c
Bitwise AND operator in c
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C language
 
C Prog. - Operators and Expressions
C Prog. - Operators and ExpressionsC Prog. - Operators and Expressions
C Prog. - Operators and Expressions
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
Deep C
Deep CDeep C
Deep C
 

Similar to C bitwise operators

Cse lecture-4.2-c bit wise operators and expression
Cse lecture-4.2-c bit wise operators and expressionCse lecture-4.2-c bit wise operators and expression
Cse lecture-4.2-c bit wise operators and expression
FarshidKhan
 
Sc
ScSc
Bitwise operators
Bitwise operatorsBitwise operators
Bitwise operators
Megha Sharma
 
Lecture 11 bitwise_operator
Lecture 11 bitwise_operatorLecture 11 bitwise_operator
Lecture 11 bitwise_operatoreShikshak
 
Bit manipulation
Bit manipulationBit manipulation
Bit manipulation
Priyanka Yadav
 
Bit shift operators
Bit shift operatorsBit shift operators
Bit shift operators
alldesign
 
09. session 9 operators and statements
09. session 9   operators and statements09. session 9   operators and statements
09. session 9 operators and statementsPhúc Đỗ
 
Bitwise Operations(1).pdf
Bitwise Operations(1).pdfBitwise Operations(1).pdf
Bitwise Operations(1).pdf
DalvinCalvin
 
Low Level Prog. (from 201-c).ppt
Low Level Prog. (from 201-c).pptLow Level Prog. (from 201-c).ppt
Low Level Prog. (from 201-c).ppt
LearnWithJCM
 
4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt
RithwikRanjan
 
Python : basic operators
Python : basic operatorsPython : basic operators
Python : basic operators
S.M. Salaquzzaman
 
Logic microoperations
Logic microoperationsLogic microoperations
Logic microoperationsNitesh Singh
 
unit 3.pptx
unit 3.pptxunit 3.pptx
unit 3.pptx
ragu nath
 
Implementation and Simulation of Ieee 754 Single-Precision Floating Point Mul...
Implementation and Simulation of Ieee 754 Single-Precision Floating Point Mul...Implementation and Simulation of Ieee 754 Single-Precision Floating Point Mul...
Implementation and Simulation of Ieee 754 Single-Precision Floating Point Mul...
inventionjournals
 
Logic Micro Operation
Logic Micro OperationLogic Micro Operation
Logic Micro Operation
mahesh kumar prajapat
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statementsCtOlaf
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
Atul Sehdev
 

Similar to C bitwise operators (20)

Cse lecture-4.2-c bit wise operators and expression
Cse lecture-4.2-c bit wise operators and expressionCse lecture-4.2-c bit wise operators and expression
Cse lecture-4.2-c bit wise operators and expression
 
Sc
ScSc
Sc
 
Bitwise operators
Bitwise operatorsBitwise operators
Bitwise operators
 
Report on c
Report on cReport on c
Report on c
 
Lecture 11 bitwise_operator
Lecture 11 bitwise_operatorLecture 11 bitwise_operator
Lecture 11 bitwise_operator
 
Bit manipulation
Bit manipulationBit manipulation
Bit manipulation
 
Bit shift operators
Bit shift operatorsBit shift operators
Bit shift operators
 
09. session 9 operators and statements
09. session 9   operators and statements09. session 9   operators and statements
09. session 9 operators and statements
 
Bitwise Operations(1).pdf
Bitwise Operations(1).pdfBitwise Operations(1).pdf
Bitwise Operations(1).pdf
 
Low Level Prog. (from 201-c).ppt
Low Level Prog. (from 201-c).pptLow Level Prog. (from 201-c).ppt
Low Level Prog. (from 201-c).ppt
 
Java - Operators
Java - OperatorsJava - Operators
Java - Operators
 
Java 2
Java 2Java 2
Java 2
 
4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt
 
Python : basic operators
Python : basic operatorsPython : basic operators
Python : basic operators
 
Logic microoperations
Logic microoperationsLogic microoperations
Logic microoperations
 
unit 3.pptx
unit 3.pptxunit 3.pptx
unit 3.pptx
 
Implementation and Simulation of Ieee 754 Single-Precision Floating Point Mul...
Implementation and Simulation of Ieee 754 Single-Precision Floating Point Mul...Implementation and Simulation of Ieee 754 Single-Precision Floating Point Mul...
Implementation and Simulation of Ieee 754 Single-Precision Floating Point Mul...
 
Logic Micro Operation
Logic Micro OperationLogic Micro Operation
Logic Micro Operation
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statements
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
 

More from Suneel Dogra

Business model
Business modelBusiness model
Business model
Suneel Dogra
 
Internet
InternetInternet
Internet
Suneel Dogra
 
Distributed databases
Distributed databasesDistributed databases
Distributed databasesSuneel Dogra
 
Data base management system
Data base management systemData base management system
Data base management systemSuneel Dogra
 
Web sitedesignpart1
Web sitedesignpart1Web sitedesignpart1
Web sitedesignpart1Suneel Dogra
 
Web sitedesignpart1
Web sitedesignpart1Web sitedesignpart1
Web sitedesignpart1Suneel Dogra
 
Internet security
Internet securityInternet security
Internet security
Suneel Dogra
 
He 12 different types of servers that every techie should know about
He 12 different types of servers that every techie should know aboutHe 12 different types of servers that every techie should know about
He 12 different types of servers that every techie should know aboutSuneel Dogra
 
Bachelor of computer application b.c.a.-2014
Bachelor of computer application b.c.a.-2014Bachelor of computer application b.c.a.-2014
Bachelor of computer application b.c.a.-2014Suneel Dogra
 
Cloud computing application
Cloud computing applicationCloud computing application
Cloud computing application
Suneel Dogra
 
Fast track to linux
Fast track to linuxFast track to linux
Fast track to linux
Suneel Dogra
 
A sorted linear array
A sorted linear array A sorted linear array
A sorted linear array
Suneel Dogra
 
String in c
String in cString in c
String in c
Suneel Dogra
 

More from Suneel Dogra (20)

Business model
Business modelBusiness model
Business model
 
Internet
InternetInternet
Internet
 
Html
HtmlHtml
Html
 
Dreamweaver
DreamweaverDreamweaver
Dreamweaver
 
Advanced html
Advanced htmlAdvanced html
Advanced html
 
Sql
SqlSql
Sql
 
File organisation
File organisationFile organisation
File organisation
 
Distributed databases
Distributed databasesDistributed databases
Distributed databases
 
Database models
Database models Database models
Database models
 
Data base management system
Data base management systemData base management system
Data base management system
 
Web sitedesignpart1
Web sitedesignpart1Web sitedesignpart1
Web sitedesignpart1
 
Web sitedesignpart1
Web sitedesignpart1Web sitedesignpart1
Web sitedesignpart1
 
Internet security
Internet securityInternet security
Internet security
 
What is the linux
What is the linuxWhat is the linux
What is the linux
 
He 12 different types of servers that every techie should know about
He 12 different types of servers that every techie should know aboutHe 12 different types of servers that every techie should know about
He 12 different types of servers that every techie should know about
 
Bachelor of computer application b.c.a.-2014
Bachelor of computer application b.c.a.-2014Bachelor of computer application b.c.a.-2014
Bachelor of computer application b.c.a.-2014
 
Cloud computing application
Cloud computing applicationCloud computing application
Cloud computing application
 
Fast track to linux
Fast track to linuxFast track to linux
Fast track to linux
 
A sorted linear array
A sorted linear array A sorted linear array
A sorted linear array
 
String in c
String in cString in c
String in c
 

Recently uploaded

Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 

Recently uploaded (20)

Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 

C bitwise operators

  • 1. C Bitwise Operators Bitwise operators are used to manipulate one or more bits from integral operands like char, int, short, long, here we will see the basics of bitwise operators, and some useful tips for manipulating the bits to achieve a task. Bitwise operators operate on individual bits of integer (int and long) values. This is useful for writing low-level hardware or OS code where the ordinary abstractions of numbers, characters, pointers, and so on, are insufficient. Bit manipulation code tends to be less "portable". Code is "portable" if without any programmer intervention it compiles and runs correctly on different types of computers. The bit wise operations are commonly used with unsigned types. These operators perform bit wise logical operations on values. Both operands must be of the same type and width: the resultant value will also be this type and width. A bitwise operator works on each bit of data. Bitwise operators are used in bit level programming the Bitwise operators supported by C language are listed in the following table. Assume variable A holds 60 and variable B holds 13 then: Operator Description Example & Binary AND Operator copies a bit to the result if it exists in both operands. (A & B) will give 12 which is 0000 1100 | Binary OR Operator copies a bit if it exists in either operand. (A | B) will give 61 which is 0011 1101 ^ Binary XOR Operator copies the bit if it is set in one operand but not both. (A ^ B) will give 49 which is 0011 0001 ~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. (~A ) will give -61 which is 1100 0011 in 2's complement form due to a signed binary number. << Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. A << 2 will give 240 which is 1111 0000 >> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. A >> 2 will give 15 which is 0000 1111 Bitwise OR – | Bitwise OR operator | takes 2 bit patterns, and perform OR operations on each pair of corresponding bits. The following example will explain it. 1010 1100 -------- OR 1110 -------- The Bitwise OR, will take pair of bits from each position, and if any one of the bit is 1, the result on that position will be 1.
  • 2. Bitwise AND – & Bitwise AND operator &, takes 2 bit patterns, and perform AND operations with it. 1010 1100 ------- AND 1000 ------- The Bitwise AND will take pair of bits from each position, and if only both the bit is 1, the result on that position will be 1 One’s Complement operator – ~ One’s complement operator (Bitwise NOT) is used to convert each “1-bit to 0-bit” and “0-bit to 1-bit”, in the given binary pattern. It is a unary operator i.e. it takes only one operand. 1001 NOT ------- 0110 ------- Bitwise XOR – ^ Bitwise XOR ^, takes 2 bit patterns and perform XOR operation with it. 0101 0110 ------ XOR 0011 ------ The Bitwise XOR will take pair of bits from each position, and if both the bits are different, the result on that position will be 1. If both bits are same, then the result on that position is 0. Bit a Bit b a & b a | b a ^ b ~a 0 0 0 0 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 0 #include<stdio.h> #include<conio.h> void main() { int a=5,b=3; printf("%dn",a|b); printf("%dn",a&b); printf("%dn",a^b); getch(); }
  • 3. Right Shift a = 0000 0011 = 3 (a<<=1) = 00000110 = 6 (a<<=2) = 00011000 = 24 (a<<=3) = 11000000 = 192 Left Shift a=11000000 =192 (a>>=1) = 01100000 = 96 (a>>=2) = 00011000 = 24 (a>>=3) = 0000 0011 = 3 a = 12 b = 10 --------------------------------- a in Binary : 0000 0000 0000 1100 b in Binary : 0000 0000 0000 1010 --------------------------------- a | b : 0000 0000 0000 1110 a & b : 0000 0000 0000 1000 a ^ b : 0000 0000 0000 0110 a | b : 0000 0000 0000 1110 = 14 a & b : 0000 0000 0000 1000 = 8 a ^ b : 0000 0000 0000 0110 = 6