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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!