+ 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
7 Respuestas
+ 6
Please show us your attempt first.
+ 6
Retag Tarek can you provide an example of the output?
+ 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
+ 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
+ 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
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.
0
Thank you all 🤗