SlideShare una empresa de Scribd logo
1 de 41
Descargar para leer sin conexión
Team Emertxe
Function and Pointer
Basics
Assignment 2
Assignment 2
Assignment 2
WAP to replace ‘n’ bits of a given number
WAP to replace ‘n’ bits of a given number
Input:
Assignment 2
WAP to replace ‘n’ bits of a given number
Input: Read integer ‘num’, number of bits ‘n’ and ‘val’
Assignment 2
WAP to replace ‘n’ bits of a given number
Input: Read integer ‘num’, number of bits ‘n’ and ‘val’
Output:
Assignment 2
WAP to replace ‘n’ bits of a given number
Input: Read integer ‘num’, number of bits ‘n’ and ‘val’
Output: Return the updated value of ‘num’ after replacing
‘n’ bits
Assignment 2
Example’s:
Assignment 2
Example’s:
➢ Input: num = 10 , n = 3 and val = 12
Assignment 2
Example’s:
➢ Input: num = 10 , n = 3 and val = 12
Step 1: Clear 3 bits from LSB of num 10 :
Assignment 2
Example’s:
➢ Input: num = 10 , n = 3 and val = 12
Step 1: Clear 3 bits from LSB of num 10 :
Assignment 2
0 0 0
1
0
1
0
0
0 0 0
0
0
1
0
0
num
num
Example’s:
➢ Input: num = 10 , n = 3 and val = 12
Step 2: Take 3 bits from LSB end of ‘val’ 12 :
Assignment 2
0 0 0
0
1
1
0
0
val
Example’s:
➢ Input: num = 10 , n = 3 and val = 12
Step 3: Replace those 3 bits in the LSB end of num 10 :
Assignment 2
0 0
0
0
1
1
0
0 0 0
1
12
Updated
‘num’
Example’s:
➢ Input: num = 15 , n = 2 and val = 1
Assignment 2
Example’s:
➢ Input: num = 15 , n = 2 and val = 1
Step 1: Clear 2 bits from LSB of num 15 :
Assignment 2
Example’s:
➢ Input: num = 15 , n = 2 and val = 1
Step 1: Clear 2 bits from LSB of num 15 :
Assignment 2
0 0 1
1
1
1
0
0
0 0 0
0
1
1
0
0
num
num
Example’s:
➢ Input: num = 15 , n = 2 and val = 1
Step 2: Take 2 bits from LSB end of val 1 :
Assignment 2
0 0 1
0
0
0
0
0
val
Example’s:
➢ Input: num = 15 , n = 2 and val = 1
Step 3: Replace those 2 bits in the LSB end of num 15 :
Assignment 2
1
0
0 1 13
1
0 0 1
0
0
Updated
‘num’
Example’s:
➢ Input: num = 7 , n = 1 and val = 2
Assignment 2
Example’s:
➢ Input: num = 7 , n = 1 and val = 2
Step 1: Clear 1 bit from LSB of num 7 :
Assignment 2
Example’s:
➢ Input: num = 7 , n = 1 and val = 2
Step 1: Clear 1 bit from LSB of num 7 :
Assignment 2
0 0 1
1
1
0
0
0
0 0 ?
1
1
0
0
0
num
num
Example’s:
➢ Input: num = 7 , n = 1 and val = 2
Step 1: Clear 1 bit from LSB of num 7 :
Assignment 2
0 0 1
1
1
0
0
0
0 0 0
1
1
0
0
0
num
num
Example’s:
➢ Input: num = 7 , n = 1 and val = 2
Step 2: Take 1 bit from LSB end of val 2 :
Assignment 2
0 0 0
1
0
0
0
0
val
Example’s:
➢ Input: num = 7 , n = 1 and val = 2
Step 3: Replace that 1 bit in the LSB end of num 7 :
Assignment 2
0
1 0 ?
1
0 0 0
0
0
Updated
‘num’
Example’s:
➢ Input: num = 7 , n = 1 and val = 2
Step 3: Replace that 1 bit in the LSB end of num 7 :
Assignment 2
0
1 0 6
1
0 0 0
0
0
Updated
‘num’
Example’s:
➢ Input: num = 8 , n = 2 and val = 7
Assignment 2
Example’s:
➢ Input: num = 8 , n = 2 and val = 7
Step 1: Clear 2 bits from LSB of num 8 :
Assignment 2
Example’s:
➢ Input: num = 8 , n = 2 and val = 7
Step 1: Clear 2 bits from LSB of num 8 :
Assignment 2
0 0 0
0
0
1
0
0
0 0 ?
?
0
1
0
0
num
num
Example’s:
➢ Input: num = 8 , n = 2 and val = 7
Step 1: Clear 2 bits from LSB of num 8 :
Assignment 2
0 0 0
0
1
0
0
0 0 0
0
1
0
0
num
num 0
0
Example’s:
➢ Input: num = 8 , n = 2 and val = 7
Step 2: Take 2 bits from LSB end of val 7 :
Assignment 2
0 0 1
1
1
0
0
0
val
Example’s:
➢ Input: num = 8 , n = 2 and val = 7
Step 3: Replace those 2 bits in the LSB end of num 8 :
Assignment 2
1
? ? ?
0
0 0 1
0
0
Updated
‘num’
1
Example’s:
➢ Input: num = 8 , n = 2 and val = 7
Step 3: Replace those 2 bits in the LSB end of num 8 :
Assignment 2
1
1 1 11
0
0 0 1
0
0
Updated
‘num’
1
Sample execution:-
Assignment 2
Sample execution:-
Assignment 2
Pre-requisites:-
Assignment 2
Pre-requisites:-
➢ Bitwise operators
Assignment 2
Pre-requisites:-
➢ Bitwise operators
➢ Functions
Assignment 2
Pre-requisites:-
➢ Bitwise operators
➢ Functions
Objective:-
Assignment 2
Pre-requisites:-
➢ Bitwise operators
➢ Functions
Objective:-
➢ To understand the concept of Bitwise operations.
Assignment 2
Team Emertxe
Thank you

Más contenido relacionado

Similar a 02_replace_n_bits.pdf

Similar a 02_replace_n_bits.pdf (13)

05_print_bits.pdf
05_print_bits.pdf05_print_bits.pdf
05_print_bits.pdf
 
Number system
Number systemNumber system
Number system
 
Chapter 7 rohith
Chapter 7 rohithChapter 7 rohith
Chapter 7 rohith
 
AES KEY EXPANSION .pptx
AES KEY EXPANSION .pptxAES KEY EXPANSION .pptx
AES KEY EXPANSION .pptx
 
CS330-Lectures Statistics And Probability
CS330-Lectures Statistics And ProbabilityCS330-Lectures Statistics And Probability
CS330-Lectures Statistics And Probability
 
Insider mathematical
Insider   mathematicalInsider   mathematical
Insider mathematical
 
03_negative_fibonacci.pdf
03_negative_fibonacci.pdf03_negative_fibonacci.pdf
03_negative_fibonacci.pdf
 
Project on digital vlsi design
Project on digital vlsi designProject on digital vlsi design
Project on digital vlsi design
 
Lec20
Lec20Lec20
Lec20
 
Unit 1 data representation and computer arithmetic
Unit 1  data representation and computer arithmeticUnit 1  data representation and computer arithmetic
Unit 1 data representation and computer arithmetic
 
Chapter 01 Basic Principles of Digital Systems
Chapter 01 Basic Principles of Digital SystemsChapter 01 Basic Principles of Digital Systems
Chapter 01 Basic Principles of Digital Systems
 
IARE_DLD_PPT_0.pdf
IARE_DLD_PPT_0.pdfIARE_DLD_PPT_0.pdf
IARE_DLD_PPT_0.pdf
 
DLD_PPT_0.pptx
DLD_PPT_0.pptxDLD_PPT_0.pptx
DLD_PPT_0.pptx
 

Más de Emertxe Information Technologies Pvt Ltd

Más de Emertxe Information Technologies Pvt Ltd (20)

premium post (1).pdf
premium post (1).pdfpremium post (1).pdf
premium post (1).pdf
 
Career Transition (1).pdf
Career Transition (1).pdfCareer Transition (1).pdf
Career Transition (1).pdf
 
10_isxdigit.pdf
10_isxdigit.pdf10_isxdigit.pdf
10_isxdigit.pdf
 
01_student_record.pdf
01_student_record.pdf01_student_record.pdf
01_student_record.pdf
 
02_swap.pdf
02_swap.pdf02_swap.pdf
02_swap.pdf
 
01_sizeof.pdf
01_sizeof.pdf01_sizeof.pdf
01_sizeof.pdf
 
07_product_matrix.pdf
07_product_matrix.pdf07_product_matrix.pdf
07_product_matrix.pdf
 
06_sort_names.pdf
06_sort_names.pdf06_sort_names.pdf
06_sort_names.pdf
 
05_fragments.pdf
05_fragments.pdf05_fragments.pdf
05_fragments.pdf
 
04_magic_square.pdf
04_magic_square.pdf04_magic_square.pdf
04_magic_square.pdf
 
03_endianess.pdf
03_endianess.pdf03_endianess.pdf
03_endianess.pdf
 
02_variance.pdf
02_variance.pdf02_variance.pdf
02_variance.pdf
 
01_memory_manager.pdf
01_memory_manager.pdf01_memory_manager.pdf
01_memory_manager.pdf
 
09_nrps.pdf
09_nrps.pdf09_nrps.pdf
09_nrps.pdf
 
11_pangram.pdf
11_pangram.pdf11_pangram.pdf
11_pangram.pdf
 
10_combinations.pdf
10_combinations.pdf10_combinations.pdf
10_combinations.pdf
 
08_squeeze.pdf
08_squeeze.pdf08_squeeze.pdf
08_squeeze.pdf
 
07_strtok.pdf
07_strtok.pdf07_strtok.pdf
07_strtok.pdf
 
06_reverserec.pdf
06_reverserec.pdf06_reverserec.pdf
06_reverserec.pdf
 
05_reverseiter.pdf
05_reverseiter.pdf05_reverseiter.pdf
05_reverseiter.pdf
 

Último

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.pptxAreebaZafar22
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
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.christianmathematics
 
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 17Celine George
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
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 FellowsMebane Rash
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
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).pptxEsquimalt MFRC
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
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
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
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.pdfDr Vijay Vishwakarma
 

Último (20)

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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
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.
 
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
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
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
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
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
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.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...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
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
 

02_replace_n_bits.pdf