SlideShare a Scribd company logo
1 of 51
Download to read offline
Team Emertxe
Function and Pointer
Basics
Assignment 6
Assignment 6
Assignment 6
WAP to put the (b-a+1) lsb’s of num into val[b:a]
WAP to put the (b-a+1) lsb’s of num into val[b:a]
Input:
Assignment 6
WAP to put the (b-a+1) lsb’s of num into val[b:a]
Input: Read integers ‘num’, ‘val’, ‘a’ and ‘b’.
Assignment 6
WAP to put the (b-a+1) lsb’s of num into val[b:a]
Input: Read integers ‘num’, ‘val’, ‘a’ and ‘b’.
Output:
Assignment 6
WAP to put the (b-a+1) lsb’s of num into val[b:a]
Input: Read integers ‘num’, ‘val’, ‘a’ and ‘b’.
Output: Return the updated value of ‘val’ after replacing
number of bits from position ‘b’.
Assignment 6
Example’s:
Assignment 6
Example’s:
➢ Input: num = 11, val = 174, a = 3 and b = 5
Assignment 6
Example’s:
➢Input: num = 11, val = 174, a = 3 and b = 5
➢Binary format of num 11 :
Assignment 6
Example’s:
➢Input: num = 11, val = 174, a = 3 and b = 5
➢Binary format of num 11 :
Assignment 6
0 0 1
1
0
1
0
0
num
Example’s:
➢Input: num = 11 ,val = 174, a = 3 and b = 5
Step 1: Find ‘n’ number of bits to be replaced in ‘val’:
n = b-a+1 = 5-3+1 = 3
Assignment 6
Example’s:
➢Input: num = 11 ,val = 174, a = 3 and b = 5
Step 2: Clear 3 bits from ‘pos’ 5 of ‘val’ 174 :
Assignment 6
1 0 0
1
1
1
0
1
0
0
0
1 0 0
1
1
val
val
Example’s:
➢Input: num = 11 ,val = 174, a = 3 and b = 5
Step 3: Fetch 3 bits from LSB end of ‘num’ 11 :
Assignment 6
0 0 1
1
0
1
0
0
num
Example’s:
➢Input: num = 11 ,val = 174, a = 3 and b = 5
Step 4: Replace those 3 bits from 5th position of ‘val’ 174:
Assignment 6
1 0
1
1
1
1
1
0 1 0
0
158
Updated
‘val’
Example’s:
➢Input: num = 15 ,val = 1, a = 3 and b = 4
Assignment 6
Example’s:
➢Input: num = 15 ,val = 1, a = 3 and b = 4
➢Binary format of num 15 :
Assignment 6
Example’s:
➢Input: num = 15 ,val = 1, a = 3 and b = 4
➢Binary format of num 15 :
Assignment 6
0 0 1
1
1
1
0
0
num
Example’s:
➢Input: num = 15 ,val = 1, a = 3 and b = 4
Step 1: Find ‘n’ number of bits to be replaced in ‘val’:
n = b-a+1 = 4-3+1 = 2
Assignment 6
Example’s:
➢Input: num = 15 ,val = 1, a = 3 and b = 4
Step 2: Clear 2 bits from ‘pos’ 4 of ‘val’ 1 :
Assignment 6
0 0 1
0
0
0
0
0 0
0
0
0
0 0 1
0
0
0
val
val
Example’s:
➢Input: num = 15 ,val = 1, a = 3 and b = 4
Step 3: Fetch 2 bits from LSB end of ‘num’ 15 :
Assignment 6
0 0 1
1
1
1
0
0
num
Example’s:
➢Input: num = 15 ,val = 1, a = 3 and b = 4
Step 4: Replace those 2 bits from 4th position of ‘val’ 1:
Assignment 6
0 0
1
1
0
1
1
0 0 1 25
Updated
‘val’
Example’s:
➢Input: num = 16, val = 15, a = 2 and b = 3
Assignment 6
Example’s:
➢Input: num = 16, val = 15, a = 2 and b = 3
➢Binary format of num 16 :
Assignment 6
Example’s:
➢Input: num = 16, val = 15, a = 2 and b = 3
➢Binary format of num 16 :
Assignment 6
? ? ?
?
?
?
?
?
num
Example’s:
➢Input: num = 16, val = 15, a = 2 and b = 3
➢Binary format of num 16 :
Assignment 6
0 0 0
0
0
0
1
0
num
Example’s:
➢Input: num = 16, val = 15, a = 2 and b = 3
Step 1: Find ‘n’ number of bits to be replaced in ‘val’:
n = b-a+1 = 3-2+1 = 2
Assignment 6
Example’s:
➢Input: num = 16, val = 15, a = 2 and b = 3
Step 2: Clear 2 bits from ‘pos’ 3 of ‘val’ 15 :
Assignment 6
0 0 1
1
1
0
0
0 1
0
?
0
0 0 1
1
?
0
val
val
Example’s:
➢Input: num = 16, val = 15, a = 2 and b = 3
Step 2: Clear 2 bits from ‘pos’ 3 of ‘val’ 15 :
Assignment 6
0 0 1
1
1
0
0
0 1
0
0
0
0 0 1
1
0
0
val
val
Example’s:
➢Input: num = 16, val = 15, a = 2 and b = 3
Step 3: Fetch 2 bits from LSB end of ‘num’ 16 :
Assignment 6
0 0 0
0
0
0
1
0
num
Example’s:
➢Input: num = 16, val = 15, a = 2 and b = 3
Step 4: Replace those 2 bits from 3rd position of ‘val’ 15:
Assignment 6
0 0
0
0
?
?
0
0 1 1 ?
Updated
‘val’
Example’s:
➢Input: num = 16, val = 15, a = 2 and b = 3
Step 4: Replace those 2 bits from 3rd position of ‘val’ 15:
Assignment 6
0 0
0
0
0
0
0
0 1 1 3
Updated
‘val’
Example’s:
➢Input: num = 13, val = 25, a = 3 and b = 5
Assignment 6
Example’s:
➢Input: num = 13, val = 25, a = 3 and b = 5
➢Binary format of num 13 :
Assignment 6
Example’s:
➢Input: num = 13, val = 25, a = 3 and b = 5
➢Binary format of num 13 :
Assignment 6
? ? ?
?
?
?
?
?
num
Example’s:
➢Input: num = 13, val = 25, a = 3 and b = 5
➢Binary format of num 13 :
Assignment 6
0 0 1
0
1
1
0
0
num
Example’s:
➢Input: num = 13, val = 25, a = 3 and b = 5
Step 1: Find ‘n’ number of bits to be replaced in ‘val’:
n = b-a+1 = 5-3+1 = 3
Assignment 6
Example’s:
➢Input: num = 13, val = 25, a = 3 and b = 5
Step 2: Clear 3 bits from ‘pos’ 5 of ‘val’ 25 :
Assignment 6
0 0 1
0
0
0
0
0 1
1
?
?
0 0 1
0
0
?
val
val
Example’s:
➢Input: num = 13, val = 25, a = 3 and b = 5
Step 2: Clear 3 bits from ‘pos’ 5 of ‘val’ 25 :
Assignment 6
0 0 1
0
0
0
0
0 1
1
0
0
0 0 1
0
0
0
val
val
Example’s:
➢Input: num = 13, val = 25, a = 3 and b = 5
Step 3: Fetch 3 bits from LSB end of ‘num’ 13 :
Assignment 6
0 0 1
0
1
1
0
0
num
Example’s:
➢Input: num = 13, val = 25, a = 3 and b = 5
Step 4: Replace those 3 bits from 5th position of ‘val’ 25:
Assignment 6
0 0
0 1
0
?
?
? 0 1 ?
Updated
‘val’
1
Example’s:
➢Input: num = 13, val = 25, a = 3 and b = 5
Step 4: Replace those 3 bits from 5th position of ‘val’ 25:
Assignment 6
0 0
0 1
0
1
0
1 0 1 41
Updated
‘val’
1
Sample execution:-
Assignment 6
Sample execution:-
Assignment 6
Pre-requisites:-
Assignment 6
Pre-requisites:-
➢ Bitwise operators
Assignment 6
Pre-requisites:-
➢ Bitwise operators
➢ Functions
Assignment 6
Pre-requisites:-
➢ Bitwise operators
➢ Functions
Objective:-
Assignment 6
Pre-requisites:-
➢ Bitwise operators
➢ Functions
Objective:-
➢ To understand the concept of Bitwise operations.
Assignment 6
Team Emertxe
Thank you

More Related Content

Similar to 06_replace_n_bits_pos.pdf (12)

01_get_n_bits.pdf
01_get_n_bits.pdf01_get_n_bits.pdf
01_get_n_bits.pdf
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
Matlab_basic2013_1.pdf
Matlab_basic2013_1.pdfMatlab_basic2013_1.pdf
Matlab_basic2013_1.pdf
 
software_Testing_Lab_Manual_for_VTU_6th.doc
software_Testing_Lab_Manual_for_VTU_6th.docsoftware_Testing_Lab_Manual_for_VTU_6th.doc
software_Testing_Lab_Manual_for_VTU_6th.doc
 
09_nrps.pdf
09_nrps.pdf09_nrps.pdf
09_nrps.pdf
 
Teoria y problemas de numeros racionales qa412 ccesa007
Teoria y problemas de numeros racionales qa412 ccesa007Teoria y problemas de numeros racionales qa412 ccesa007
Teoria y problemas de numeros racionales qa412 ccesa007
 
17_positive_fibonacci.pdf
17_positive_fibonacci.pdf17_positive_fibonacci.pdf
17_positive_fibonacci.pdf
 
Data Structure and Algorithm
Data Structure and AlgorithmData Structure and Algorithm
Data Structure and Algorithm
 
18_negative_fibonacci.pdf
18_negative_fibonacci.pdf18_negative_fibonacci.pdf
18_negative_fibonacci.pdf
 
Chapter 6 Balagurusamy Programming ANSI in c
Chapter 6  Balagurusamy Programming ANSI  in cChapter 6  Balagurusamy Programming ANSI  in c
Chapter 6 Balagurusamy Programming ANSI in c
 
Python - Lecture 6
Python - Lecture 6Python - Lecture 6
Python - Lecture 6
 
Number system
Number systemNumber system
Number system
 

More from Emertxe Information Technologies Pvt Ltd

More from 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
 
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
 
04_itoa.pdf
04_itoa.pdf04_itoa.pdf
04_itoa.pdf
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

06_replace_n_bits_pos.pdf