How can I solve this problem? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I solve this problem?

write a function with input and no output that takes to decimal numbers from the user and bit position in the first and in the second one and swap the two bits and print the result

6th Sep 2018, 2:33 AM
Retag Tarek
Retag Tarek - avatar
7 Answers
+ 6
Please show us your attempt first.
6th Sep 2018, 2:49 AM
Nikhil
Nikhil - avatar
+ 6
Retag Tarek can you provide an example of the output?
6th Sep 2018, 4:23 AM
Nikhil
Nikhil - avatar
+ 3
Retag Tarek That is a interesting one. I have not dealt with bits much. If you are willing try www.stackexchange.com search bit manipulation. If you find nothing try to skim this and ask your question. Hope it helps. https://www.tutorialspoint.com/cprogramming/c_bit_fields.htm
6th Sep 2018, 4:23 AM
Manual
Manual - avatar
+ 2
Retag Tarek I made this swaps the values of two defined bits. currently no user input. edit : could not make it accept decimals. https://code.sololearn.com/caFH1E0pKENx/?ref=app
6th Sep 2018, 4:58 AM
Manual
Manual - avatar
+ 2
if x,y are the number and a,b the bits position: xnew=(x & (~(1<<a)))|(((y>>b)&1)<<a) for ynew take the symetric formula google c bitwise operator for more info
6th Sep 2018, 5:44 AM
VcC
VcC - avatar
0
Nikhil I dunno how to acess bits in that way and I can't even find it in google so your help would be appreciated.
6th Sep 2018, 2:51 AM
Retag Tarek
Retag Tarek - avatar
0
Thank you all 🤗
7th Sep 2018, 12:02 AM
Retag Tarek
Retag Tarek - avatar