Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program with a function 'fun' that takes an integer as its argument and changes the n-th bit (counting starting from the right, and

Write a program with a function 'fun' that takes
an integer as its argument and changes the n-th bit
(counting starting from the right, and with 1)
in its binary-number representation and replaces it
with 1 if it is 0 and with 0 if it is 1, and then
returns the integer with replacements.
For instance, fun(6, 2) should return 4 because
in 6 = 110(2) we replace 1 with 0 to obtain 100.
Similarly, fun(9, 3) = 13 since we replace 9 = 1001(2)
with 1101(2).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions