SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Computer Programming
Basic of Bits
• In C "A bit field is set up with a structure
declaration that labels each field and
determines its width."
Bit operator
Shift operator
• There are two types of operator used in c
language.
• Left shit operator (<<)
• Right shift operator (>>)
Left shift operator
Right shift operator
Bit field
• A bit field is a term used in comp
programming to store multiple, logical
where each of the sets of bits, and
single bit can be addressed.
Cont,,
Bit Fields allow the packing of data in a structure. This is especially useful when memory or data storage
is at a premium. Typical examples:
Packing several objects into a machine word. e.g. 1 bit flags can be compacted -- Symbol tables in
compilers.
Reading external file formats -- non-standard file formats could be read in. E.g. 9 bit integers.
C lets us do this in a structure definition by putting :bit length after the variable. i.e.
struct packed_struct { unsigned int f1:1; unsigned int f2:1; unsigned int f3:1; unsigned int f4:1; unsigned int
type:4; unsigned int funny_int:9; } pack;
Here the packed_struct contains 6 members: Four 1 bit flags f1..f3, a 4 bit type and a 9 bit funny_int.
C automatically packs the above bit fields as compactly as possible, provided that the maximum length of
the field is less than or equal to the integer word length of the computer. If this is not the case then
some compilers may allow memory overlap for the fields whilst other would store the next field in the
next word (see comments on bit fiels portability below).
Access members as usual via:
pack.type = 7;
Bit field declaration
Cont,,
Rotating bits
If I were to try and `rotateRight(5):
y becomes 11111110
z becomes 01100000
Then g becomes 111111110
Bits, Bits operator, bitwise function

Weitere ähnliche Inhalte

Was ist angesagt?

Conference presentation final
Conference presentation finalConference presentation final
Conference presentation final
ALYAA AL-BARRAK
 
Ppt fnr arbitrary length small domain block cipher proposal
Ppt fnr  arbitrary length small domain block cipher proposalPpt fnr  arbitrary length small domain block cipher proposal
Ppt fnr arbitrary length small domain block cipher proposal
Karunakar Saroj
 

Was ist angesagt? (12)

Model Fields in Odoo 15
 Model Fields in Odoo 15 Model Fields in Odoo 15
Model Fields in Odoo 15
 
Coa unit 3 part 2 cisc vs risc
Coa unit 3 part 2 cisc vs riscCoa unit 3 part 2 cisc vs risc
Coa unit 3 part 2 cisc vs risc
 
Conference presentation final
Conference presentation finalConference presentation final
Conference presentation final
 
Odoo ORM Methods | Object Relational Mapping in Odoo15
Odoo ORM Methods | Object Relational Mapping in Odoo15 Odoo ORM Methods | Object Relational Mapping in Odoo15
Odoo ORM Methods | Object Relational Mapping in Odoo15
 
Pi - System Programming Language
Pi - System Programming LanguagePi - System Programming Language
Pi - System Programming Language
 
Ai popular search algorithms
Ai   popular search algorithmsAi   popular search algorithms
Ai popular search algorithms
 
instruction set Architecture.....(ISA)
instruction set Architecture.....(ISA)instruction set Architecture.....(ISA)
instruction set Architecture.....(ISA)
 
06 mips-isa
06 mips-isa06 mips-isa
06 mips-isa
 
7
77
7
 
FNR : Arbitrary length small domain block cipher proposal
FNR : Arbitrary length small domain block cipher proposalFNR : Arbitrary length small domain block cipher proposal
FNR : Arbitrary length small domain block cipher proposal
 
RELATION BETWEEN DATA WORD SIZE AND INSTRUCTION WORD SIZE- Dspa word size
RELATION BETWEEN DATA WORD SIZE AND INSTRUCTION WORD SIZE- Dspa word sizeRELATION BETWEEN DATA WORD SIZE AND INSTRUCTION WORD SIZE- Dspa word size
RELATION BETWEEN DATA WORD SIZE AND INSTRUCTION WORD SIZE- Dspa word size
 
Ppt fnr arbitrary length small domain block cipher proposal
Ppt fnr  arbitrary length small domain block cipher proposalPpt fnr  arbitrary length small domain block cipher proposal
Ppt fnr arbitrary length small domain block cipher proposal
 

Andere mochten auch

Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,
Ahmad55ali
 
Pautas en los principios constitucionales como solución a los problemas de fi...
Pautas en los principios constitucionales como solución a los problemas de fi...Pautas en los principios constitucionales como solución a los problemas de fi...
Pautas en los principios constitucionales como solución a los problemas de fi...
Francisco Javier Duran
 

Andere mochten auch (20)

Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,
 
Manejo integrado de_papa[1]
Manejo integrado de_papa[1]Manejo integrado de_papa[1]
Manejo integrado de_papa[1]
 
Presentación1
Presentación1Presentación1
Presentación1
 
I migliori Spot 2016
I migliori Spot 2016I migliori Spot 2016
I migliori Spot 2016
 
summer-internship-report-2015
summer-internship-report-2015summer-internship-report-2015
summer-internship-report-2015
 
Trabajo final-abel (3)
Trabajo final-abel (3)Trabajo final-abel (3)
Trabajo final-abel (3)
 
Trabajo final-abel
Trabajo final-abelTrabajo final-abel
Trabajo final-abel
 
Programas Comerciales para Simulación de Procesos Químicos
Programas Comerciales para Simulación de Procesos QuímicosProgramas Comerciales para Simulación de Procesos Químicos
Programas Comerciales para Simulación de Procesos Químicos
 
Manual de Buenas Prácticas y Reglamento de Funcionamiento para las Oficinas d...
Manual de Buenas Prácticas y Reglamento de Funcionamiento para las Oficinas d...Manual de Buenas Prácticas y Reglamento de Funcionamiento para las Oficinas d...
Manual de Buenas Prácticas y Reglamento de Funcionamiento para las Oficinas d...
 
Pautas en los principios constitucionales como solución a los problemas de fi...
Pautas en los principios constitucionales como solución a los problemas de fi...Pautas en los principios constitucionales como solución a los problemas de fi...
Pautas en los principios constitucionales como solución a los problemas de fi...
 
Presentación
PresentaciónPresentación
Presentación
 
Engargolado
EngargoladoEngargolado
Engargolado
 
Pso
PsoPso
Pso
 
PSO internship
PSO internshipPSO internship
PSO internship
 
Qatar Country Risk
Qatar Country RiskQatar Country Risk
Qatar Country Risk
 
Pso(oda)
Pso(oda)Pso(oda)
Pso(oda)
 
Pakistan state Oil (PSO)
Pakistan state Oil (PSO)Pakistan state Oil (PSO)
Pakistan state Oil (PSO)
 
Pso introduction
Pso introductionPso introduction
Pso introduction
 
PSO
PSOPSO
PSO
 
Pakistan State Oil Company Limited
Pakistan State Oil Company LimitedPakistan State Oil Company Limited
Pakistan State Oil Company Limited
 

Ähnlich wie Bits, Bits operator, bitwise function

Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuChapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structu
EstelaJeffery653
 
10 -bits_and_bytes
10  -bits_and_bytes10  -bits_and_bytes
10 -bits_and_bytes
Hector Garzo
 

Ähnlich wie Bits, Bits operator, bitwise function (20)

Embedded C - Lecture 4
Embedded C - Lecture 4Embedded C - Lecture 4
Embedded C - Lecture 4
 
8871077.ppt
8871077.ppt8871077.ppt
8871077.ppt
 
A nice 64-bit error in C
A  nice 64-bit error in CA  nice 64-bit error in C
A nice 64-bit error in C
 
C interview questions
C interview questionsC interview questions
C interview questions
 
Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuChapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structu
 
10 -bits_and_bytes
10  -bits_and_bytes10  -bits_and_bytes
10 -bits_and_bytes
 
C som-programmeringssprog-bt
C som-programmeringssprog-btC som-programmeringssprog-bt
C som-programmeringssprog-bt
 
Embedded c
Embedded cEmbedded c
Embedded c
 
C programming unit 01
C programming unit 01C programming unit 01
C programming unit 01
 
Notes of programming
Notes of programmingNotes of programming
Notes of programming
 
C –FAQ:
C –FAQ:C –FAQ:
C –FAQ:
 
mdc_ppt
mdc_pptmdc_ppt
mdc_ppt
 
C programming session10
C programming  session10C programming  session10
C programming session10
 
C- language Lecture 6
C- language Lecture 6C- language Lecture 6
C- language Lecture 6
 
Advanced+pointers
Advanced+pointersAdvanced+pointers
Advanced+pointers
 
Embedded C programming session10
Embedded C programming  session10Embedded C programming  session10
Embedded C programming session10
 
Clanguage
ClanguageClanguage
Clanguage
 
Advanced Microprocessors
Advanced MicroprocessorsAdvanced Microprocessors
Advanced Microprocessors
 
C programming language
C programming languageC programming language
C programming language
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 

Kürzlich hochgeladen

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Kürzlich hochgeladen (20)

Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

Bits, Bits operator, bitwise function

  • 2. Basic of Bits • In C "A bit field is set up with a structure declaration that labels each field and determines its width."
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. Shift operator • There are two types of operator used in c language. • Left shit operator (<<) • Right shift operator (>>)
  • 10.
  • 12.
  • 13.
  • 14. Bit field • A bit field is a term used in comp programming to store multiple, logical where each of the sets of bits, and single bit can be addressed.
  • 15. Cont,, Bit Fields allow the packing of data in a structure. This is especially useful when memory or data storage is at a premium. Typical examples: Packing several objects into a machine word. e.g. 1 bit flags can be compacted -- Symbol tables in compilers. Reading external file formats -- non-standard file formats could be read in. E.g. 9 bit integers. C lets us do this in a structure definition by putting :bit length after the variable. i.e. struct packed_struct { unsigned int f1:1; unsigned int f2:1; unsigned int f3:1; unsigned int f4:1; unsigned int type:4; unsigned int funny_int:9; } pack; Here the packed_struct contains 6 members: Four 1 bit flags f1..f3, a 4 bit type and a 9 bit funny_int. C automatically packs the above bit fields as compactly as possible, provided that the maximum length of the field is less than or equal to the integer word length of the computer. If this is not the case then some compilers may allow memory overlap for the fields whilst other would store the next field in the next word (see comments on bit fiels portability below). Access members as usual via: pack.type = 7;
  • 18. Rotating bits If I were to try and `rotateRight(5): y becomes 11111110 z becomes 01100000 Then g becomes 111111110