SlideShare a Scribd company logo
1 of 41
Download to read offline
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

More Related Content

Similar to 02_replace_n_bits.pdf

Similar to 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
 

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

Recently uploaded

PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
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.MaryamAhmad92
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
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
 
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
 
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
 
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
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 

Recently uploaded (20)

PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
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.
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
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Ữ Â...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
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
 
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
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
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
 
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
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

02_replace_n_bits.pdf