SlideShare a Scribd company logo
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
Bits, Bits operator, bitwise function
Bits, Bits operator, bitwise function
Bits, Bits operator, bitwise function
Bits, Bits operator, bitwise function
Shift operator
• There are two types of operator used in c
language.
• Left shit operator (<<)
• Right shift operator (>>)
Left shift operator
Bits, Bits operator, bitwise function
Right shift operator
Bits, Bits operator, bitwise function
Bits, Bits operator, bitwise function
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

More Related Content

PPSX
5bit field
PPTX
Things to Remember When Developing 64-bit Software
PDF
HTTP 완벽가이드 16장
PPTX
PPT
Mips architecture
PPT
Chap 11-1
PDF
Fletcher Framework for Programming FPGA
PPT
An Introduction To Chord Input
5bit field
Things to Remember When Developing 64-bit Software
HTTP 완벽가이드 16장
Mips architecture
Chap 11-1
Fletcher Framework for Programming FPGA
An Introduction To Chord Input

What's hot (12)

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

Viewers also liked (20)

PPTX
Global variables, sorting static variables,function and arrays,
PDF
Manejo integrado de_papa[1]
PPTX
Presentación1
PPTX
I migliori Spot 2016
DOCX
summer-internship-report-2015
PDF
Trabajo final-abel (3)
PDF
Trabajo final-abel
PPTX
Programas Comerciales para Simulación de Procesos Químicos
PDF
Manual de Buenas Prácticas y Reglamento de Funcionamiento para las Oficinas d...
PDF
Pautas en los principios constitucionales como solución a los problemas de fi...
PPTX
Presentación
DOCX
Engargolado
PPT
DOCX
PSO internship
PPTX
Qatar Country Risk
PPTX
Pso(oda)
PPTX
Pakistan state Oil (PSO)
PDF
Pso introduction
PPTX
PPTX
Pakistan State Oil Company Limited
Global variables, sorting static variables,function and arrays,
Manejo integrado de_papa[1]
Presentación1
I migliori Spot 2016
summer-internship-report-2015
Trabajo final-abel (3)
Trabajo final-abel
Programas Comerciales para Simulación de Procesos Químicos
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...
Presentación
Engargolado
PSO internship
Qatar Country Risk
Pso(oda)
Pakistan state Oil (PSO)
Pso introduction
Pakistan State Oil Company Limited
Ad

Similar to Bits, Bits operator, bitwise function (20)

PDF
Embedded C - Lecture 4
PPT
8871077.ppt
PDF
A nice 64-bit error in C
PDF
C interview questions
DOCX
Chapter 1SyllabusCatalog Description Computer structu
PDF
10 -bits_and_bytes
PPTX
Structures_and_Files[1] - Read-Only.pptx
PDF
C som-programmeringssprog-bt
PDF
Embedded c
PPS
C programming unit 01
PDF
Notes of programming
PDF
PDF
C programming session10
PDF
C- language Lecture 6
PPT
Advanced+pointers
PPTX
Embedded C programming session10
PPS
Clanguage
PDF
Advanced Microprocessors
PDF
C programming language
Embedded C - Lecture 4
8871077.ppt
A nice 64-bit error in C
C interview questions
Chapter 1SyllabusCatalog Description Computer structu
10 -bits_and_bytes
Structures_and_Files[1] - Read-Only.pptx
C som-programmeringssprog-bt
Embedded c
C programming unit 01
Notes of programming
C programming session10
C- language Lecture 6
Advanced+pointers
Embedded C programming session10
Clanguage
Advanced Microprocessors
C programming language

Recently uploaded (20)

PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
advance database management system book.pdf
PDF
Trump Administration's workforce development strategy
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Computing-Curriculum for Schools in Ghana
PDF
1_English_Language_Set_2.pdf probationary
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
What if we spent less time fighting change, and more time building what’s rig...
PPTX
Lesson notes of climatology university.
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Hazard Identification & Risk Assessment .pdf
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
advance database management system book.pdf
Trump Administration's workforce development strategy
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Computing-Curriculum for Schools in Ghana
1_English_Language_Set_2.pdf probationary
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
What if we spent less time fighting change, and more time building what’s rig...
Lesson notes of climatology university.
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Chinmaya Tiranga quiz Grand Finale.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Hazard Identification & Risk Assessment .pdf
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
LDMMIA Reiki Yoga Finals Review Spring Summer
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Final Presentation General Medicine 03-08-2024.pptx
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE

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."
  • 8. Shift operator • There are two types of operator used in c language. • Left shit operator (<<) • Right shift operator (>>)
  • 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