Module 00 Bitwise Operators in C

Tushar B Kute
Tushar B KuteResearcher at http://mitu.co.in
See through C
Module 0
Bitwise operators
Tushar B Kute
http://tusharkute.com
What is bitwise structure?
● The smallest type is of 8 bits (char).
● Sometimes we need only a single bit.
● For instance, storing the status of the lights in 8 rooms:
● We need to define an array of at least 8 chars.
If the light of room 3 is turned on the value of
the third char is 1, otherwise 0.
● Total array of 64 bits.
EXPENSIVE in place and time!!!
What is bitwise structure?
● It is better to define only 8 bits since a bit can also store the
values 0 or 1.
● But the problem is that there is no C type which is
1 bit long (char is the longer with 1 byte).
● Solution: define a char (8 bits) but refer to each bit separately.
● Bitwise operators, introduced by the C language, provide one
of its more powerful tools for using and manipulating memory.
They give the language the real power of a “low-level
language”.
What is bitwise structure?
● Accessing bits directly is fast and efficient, especially if you
are writing a real-time application.
● A single bit cannot be accessed directly,
since it has no address of its own.
● The language introduces the bitwise operators, which
help in manipulating a
single bit of a byte.
● bitwise operators may be used on integral types only
(unsigned types are preferable).
Bitwise Operators
& bitwise AND
| bitwise OR
^ bitwise XOR
~ 1’s compliment
<< Shift left
>> Shift right
All these operators can be suffixed with =
For instance a &= b; is the same as a = a & b;
Bitwise operators: truth table
a 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
Bitwise operators: Examples
11010011
&
10001100
------------
10000000
11010011
|
10001100
------------
11011111
11010011
^
10001100
------------
01011111
~11010011
------------
00101100
11010011>>3
------------
00011010
11010011<<3
------------
10011000
Thank you
This presentation is created using LibreOffice Impress 3.6.2.2
1 of 8

Recommended

Programming in c Arrays by
Programming in c ArraysProgramming in c Arrays
Programming in c Arraysjanani thirupathi
23.7K views31 slides
OPERATORS OF C++ by
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++ANANT VYAS
362 views24 slides
Constructors in C++ by
Constructors in C++Constructors in C++
Constructors in C++RubaNagarajan
490 views12 slides
Set methods in python by
Set methods in pythonSet methods in python
Set methods in pythondeepalishinkar1
292 views25 slides
Python recursion by
Python recursionPython recursion
Python recursionProf. Dr. K. Adisesha
679 views16 slides

More Related Content

What's hot

Python ppt by
Python pptPython ppt
Python pptAnush verma
2.4K views89 slides
7.data types in c# by
7.data types in c#7.data types in c#
7.data types in c#Zeeshan Ahmad
4.1K views10 slides
9. ES6 | Let And Const | TypeScript | JavaScript by
9. ES6 | Let And Const | TypeScript | JavaScript9. ES6 | Let And Const | TypeScript | JavaScript
9. ES6 | Let And Const | TypeScript | JavaScriptpcnmtutorials
503 views11 slides
Datatypes in c by
Datatypes in cDatatypes in c
Datatypes in cCGC Technical campus,Mohali
588 views16 slides
Exception Handling by
Exception HandlingException Handling
Exception Handlingbackdoor
1.8K views27 slides
2. bit fields union enum by
2. bit fields  union  enum2. bit fields  union  enum
2. bit fields union enumhasan Mohammad
293 views7 slides

What's hot(20)

9. ES6 | Let And Const | TypeScript | JavaScript by pcnmtutorials
9. ES6 | Let And Const | TypeScript | JavaScript9. ES6 | Let And Const | TypeScript | JavaScript
9. ES6 | Let And Const | TypeScript | JavaScript
pcnmtutorials503 views
Exception Handling by backdoor
Exception HandlingException Handling
Exception Handling
backdoor1.8K views
Python Functions Tutorial | Working With Functions In Python | Python Trainin... by Edureka!
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!1.3K views
Pointers and call by value, reference, address in C by Syed Mustafa
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
Syed Mustafa4.9K views
C Structures and Unions by Dhrumil Patel
C Structures and UnionsC Structures and Unions
C Structures and Unions
Dhrumil Patel7.5K views
Python GUI Programming by RTS Tech
Python GUI ProgrammingPython GUI Programming
Python GUI Programming
RTS Tech680 views
JavaScript - Chapter 10 - Strings and Arrays by WebStackAcademy
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
WebStackAcademy1.7K views

Viewers also liked

Operators in C Programming by
Operators in C ProgrammingOperators in C Programming
Operators in C ProgrammingJasleen Kaur (Chandigarh University)
5.8K views37 slides
C – operators and expressions by
C – operators and expressionsC – operators and expressions
C – operators and expressionsChukka Nikhil Chakravarthy
15.9K views16 slides
Unit 4. Operators and Expression by
Unit 4. Operators and Expression  Unit 4. Operators and Expression
Unit 4. Operators and Expression Ashim Lamichhane
1.6K views39 slides
Java String by
Java String Java String
Java String SATYAM SHRIVASTAV
5K views28 slides
Truth table by
Truth tableTruth table
Truth tableAbdur Rehman
8.8K views22 slides
Introduction to Java Strings, By Kavita Ganesan by
Introduction to Java Strings, By Kavita GanesanIntroduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanKavita Ganesan
9.8K views65 slides

Similar to Module 00 Bitwise Operators in C

Low Level Prog. (from 201-c).ppt by
Low Level Prog. (from 201-c).pptLow Level Prog. (from 201-c).ppt
Low Level Prog. (from 201-c).pptLearnWithJCM
4 views27 slides
Bitwise Operations(1).pdf by
Bitwise Operations(1).pdfBitwise Operations(1).pdf
Bitwise Operations(1).pdfDalvinCalvin
4 views16 slides
Data efficiency on BEAM - Choose the right data representation by Dmytro Lyto... by
Data efficiency on BEAM - Choose the right data representation by Dmytro Lyto...Data efficiency on BEAM - Choose the right data representation by Dmytro Lyto...
Data efficiency on BEAM - Choose the right data representation by Dmytro Lyto...Magnus Sedlacek
20 views29 slides
Data type by
Data typeData type
Data typemyrajendra
951 views28 slides
Advance computer architecture by
Advance computer architectureAdvance computer architecture
Advance computer architecturesuma1991
1.2K views8 slides
Cse lecture-4.2-c bit wise operators and expression by
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 expressionFarshidKhan
188 views19 slides

Similar to Module 00 Bitwise Operators in C(20)

Low Level Prog. (from 201-c).ppt by LearnWithJCM
Low Level Prog. (from 201-c).pptLow Level Prog. (from 201-c).ppt
Low Level Prog. (from 201-c).ppt
LearnWithJCM4 views
Data efficiency on BEAM - Choose the right data representation by Dmytro Lyto... by Magnus Sedlacek
Data efficiency on BEAM - Choose the right data representation by Dmytro Lyto...Data efficiency on BEAM - Choose the right data representation by Dmytro Lyto...
Data efficiency on BEAM - Choose the right data representation by Dmytro Lyto...
Magnus Sedlacek20 views
Advance computer architecture by suma1991
Advance computer architectureAdvance computer architecture
Advance computer architecture
suma19911.2K views
Cse lecture-4.2-c bit wise operators and expression by FarshidKhan
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
FarshidKhan188 views
Types of instructions by ihsanjamil
Types of instructionsTypes of instructions
Types of instructions
ihsanjamil103.6K views
Code generation in Compiler Design by Kuppusamy P
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
Kuppusamy P968 views
Report on c by jasmeen kr
Report on cReport on c
Report on c
jasmeen kr11.5K views
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx by nyomans1
Q-Step_WS_02102019_Practical_introduction_to_Python.pptxQ-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
nyomans11 view
Register allocation and assignment by Karthi Keyan
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
Karthi Keyan28.9K views
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf by Michpice
Q-Step_WS_02102019_Practical_introduction_to_Python.pdfQ-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Michpice1 view
Lesson4.2 u4 l1 binary squences by Lexume1
Lesson4.2 u4 l1 binary squencesLesson4.2 u4 l1 binary squences
Lesson4.2 u4 l1 binary squences
Lexume184 views

More from Tushar B Kute

Apache Pig: A big data processor by
Apache Pig: A big data processorApache Pig: A big data processor
Apache Pig: A big data processorTushar B Kute
3.2K views50 slides
01 Introduction to Android by
01 Introduction to Android01 Introduction to Android
01 Introduction to AndroidTushar B Kute
868 views15 slides
Ubuntu OS and it's Flavours by
Ubuntu OS and it's FlavoursUbuntu OS and it's Flavours
Ubuntu OS and it's FlavoursTushar B Kute
1.7K views34 slides
Install Drupal in Ubuntu by Tushar B. Kute by
Install Drupal in Ubuntu by Tushar B. KuteInstall Drupal in Ubuntu by Tushar B. Kute
Install Drupal in Ubuntu by Tushar B. KuteTushar B Kute
893 views25 slides
Install Wordpress in Ubuntu Linux by Tushar B. Kute by
Install Wordpress in Ubuntu Linux by Tushar B. KuteInstall Wordpress in Ubuntu Linux by Tushar B. Kute
Install Wordpress in Ubuntu Linux by Tushar B. KuteTushar B Kute
739 views26 slides
Share File easily between computers using sftp by
Share File easily between computers using sftpShare File easily between computers using sftp
Share File easily between computers using sftpTushar B Kute
2.2K views29 slides

More from Tushar B Kute(20)

Apache Pig: A big data processor by Tushar B Kute
Apache Pig: A big data processorApache Pig: A big data processor
Apache Pig: A big data processor
Tushar B Kute3.2K views
01 Introduction to Android by Tushar B Kute
01 Introduction to Android01 Introduction to Android
01 Introduction to Android
Tushar B Kute868 views
Ubuntu OS and it's Flavours by Tushar B Kute
Ubuntu OS and it's FlavoursUbuntu OS and it's Flavours
Ubuntu OS and it's Flavours
Tushar B Kute1.7K views
Install Drupal in Ubuntu by Tushar B. Kute by Tushar B Kute
Install Drupal in Ubuntu by Tushar B. KuteInstall Drupal in Ubuntu by Tushar B. Kute
Install Drupal in Ubuntu by Tushar B. Kute
Tushar B Kute893 views
Install Wordpress in Ubuntu Linux by Tushar B. Kute by Tushar B Kute
Install Wordpress in Ubuntu Linux by Tushar B. KuteInstall Wordpress in Ubuntu Linux by Tushar B. Kute
Install Wordpress in Ubuntu Linux by Tushar B. Kute
Tushar B Kute739 views
Share File easily between computers using sftp by Tushar B Kute
Share File easily between computers using sftpShare File easily between computers using sftp
Share File easily between computers using sftp
Tushar B Kute2.2K views
Signal Handling in Linux by Tushar B Kute
Signal Handling in LinuxSignal Handling in Linux
Signal Handling in Linux
Tushar B Kute10.4K views
Implementation of FIFO in Linux by Tushar B Kute
Implementation of FIFO in LinuxImplementation of FIFO in Linux
Implementation of FIFO in Linux
Tushar B Kute3.3K views
Implementation of Pipe in Linux by Tushar B Kute
Implementation of Pipe in LinuxImplementation of Pipe in Linux
Implementation of Pipe in Linux
Tushar B Kute5.2K views
Basic Multithreading using Posix Threads by Tushar B Kute
Basic Multithreading using Posix ThreadsBasic Multithreading using Posix Threads
Basic Multithreading using Posix Threads
Tushar B Kute1.5K views
Part 04 Creating a System Call in Linux by Tushar B Kute
Part 04 Creating a System Call in LinuxPart 04 Creating a System Call in Linux
Part 04 Creating a System Call in Linux
Tushar B Kute3.8K views
Part 03 File System Implementation in Linux by Tushar B Kute
Part 03 File System Implementation in LinuxPart 03 File System Implementation in Linux
Part 03 File System Implementation in Linux
Tushar B Kute3.4K views
Part 02 Linux Kernel Module Programming by Tushar B Kute
Part 02 Linux Kernel Module ProgrammingPart 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module Programming
Tushar B Kute3.6K views
Part 01 Linux Kernel Compilation (Ubuntu) by Tushar B Kute
Part 01 Linux Kernel Compilation (Ubuntu)Part 01 Linux Kernel Compilation (Ubuntu)
Part 01 Linux Kernel Compilation (Ubuntu)
Tushar B Kute3.7K views
Open source applications softwares by Tushar B Kute
Open source applications softwaresOpen source applications softwares
Open source applications softwares
Tushar B Kute1K views
Introduction to Ubuntu Edge Operating System (Ubuntu Touch) by Tushar B Kute
Introduction to Ubuntu Edge Operating System (Ubuntu Touch)Introduction to Ubuntu Edge Operating System (Ubuntu Touch)
Introduction to Ubuntu Edge Operating System (Ubuntu Touch)
Tushar B Kute5.6K views
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B KuteUnit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Tushar B Kute3.9K views
Technical blog by Engineering Students of Sandip Foundation, itsitrc by Tushar B Kute
Technical blog by Engineering Students of Sandip Foundation, itsitrcTechnical blog by Engineering Students of Sandip Foundation, itsitrc
Technical blog by Engineering Students of Sandip Foundation, itsitrc
Tushar B Kute870 views
Chapter 01 Introduction to Java by Tushar B Kute by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
Tushar B Kute3K views
Chapter 02: Classes Objects and Methods Java by Tushar B Kute by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute8.4K views

Recently uploaded

SUGCON ANZ Presentation V2.1 Final.pptx by
SUGCON ANZ Presentation V2.1 Final.pptxSUGCON ANZ Presentation V2.1 Final.pptx
SUGCON ANZ Presentation V2.1 Final.pptxJack Spektor
22 views34 slides
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit... by
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...Deltares
13 views34 slides
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... by
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...Deltares
10 views32 slides
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the... by
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...Deltares
6 views22 slides
MariaDB stored procedures and why they should be improved by
MariaDB stored procedures and why they should be improvedMariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improvedFederico Razzoli
8 views32 slides
HarshithAkkapelli_Presentation.pdf by
HarshithAkkapelli_Presentation.pdfHarshithAkkapelli_Presentation.pdf
HarshithAkkapelli_Presentation.pdfharshithakkapelli
11 views16 slides

Recently uploaded(20)

SUGCON ANZ Presentation V2.1 Final.pptx by Jack Spektor
SUGCON ANZ Presentation V2.1 Final.pptxSUGCON ANZ Presentation V2.1 Final.pptx
SUGCON ANZ Presentation V2.1 Final.pptx
Jack Spektor22 views
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit... by Deltares
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...
Deltares13 views
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... by Deltares
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
Deltares10 views
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the... by Deltares
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
Deltares6 views
MariaDB stored procedures and why they should be improved by Federico Razzoli
MariaDB stored procedures and why they should be improvedMariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improved
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... by Marc Müller
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Marc Müller37 views
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... by Marc Müller
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
Marc Müller38 views
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon by Deltares
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - AfternoonDSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon
Deltares15 views
Headless JS UG Presentation.pptx by Jack Spektor
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptx
Jack Spektor7 views
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs by Deltares
DSD-INT 2023 The Danube Hazardous Substances Model - KovacsDSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
Deltares8 views
Citi TechTalk Session 2: Kafka Deep Dive by confluent
Citi TechTalk Session 2: Kafka Deep DiveCiti TechTalk Session 2: Kafka Deep Dive
Citi TechTalk Session 2: Kafka Deep Dive
confluent17 views
What Can Employee Monitoring Software Do?​ by wAnywhere
What Can Employee Monitoring Software Do?​What Can Employee Monitoring Software Do?​
What Can Employee Monitoring Software Do?​
wAnywhere21 views
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut... by Deltares
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
Deltares6 views
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema by Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - GeertsemaDSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
Deltares17 views

Module 00 Bitwise Operators in C