SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Ähnlich wie 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
 

Mehr von Emertxe Information Technologies Pvt Ltd

Mehr von 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
 

Kürzlich hochgeladen

Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
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
QucHHunhnh
 

Kürzlich hochgeladen (20)

Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
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: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
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
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
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
 

02_replace_n_bits.pdf