Will u please help me to understand this?


Define a function called flip_bit that takes the inputs (number, n).
Flip the nth bit (with the ones bit being the first bit) and store it in result.
Return the result of calling bin(result).


Okay, this is the course you've mentioned, right?


Personally, this course was hard for me, too (I was literally just finished working this course a few minutes ago). But I'll try my best to help, BASED ON MY OBSERVATION.

You understand this part, right?

The purpose of this code is to flip the nth bit in the number input (flip in binary means turning zeroes into ones–0 into 1–and vice versa).

For example: printing flip_bit(0b111,2) will flip the second-from-right bit (n=2) of 0b111, so the result will be 0b101.

I didn't really get the meaning of "with the ones bit being the first bit" – someone, help?

Well, you must have understood this part as well.

Now, there's a hint inside the course, if you haven't read it yet:

Use the << operator to move your mask into place and the ^ operator to flip your desired bit.

From what you've learned from the course(s) before, you can make XOR mask to make the code works. Combine the n input and << operator (I am not spoiling – this is written in the course as the example. I really suggest that you re-read this course's description and example).

Well, that's it. Good luck. Anybody wanna revise or add something to this reply, go ahead.


Good job. I have no idea what your're taking about... but Good job. :confused: <--- that was my face.... but it seems to have done a good job.


Hey, which part did you not understand? Perhaps I can help with a more focused and understandable explanation?
It always sucks to stuck in a course and not being able to get it done because we didn't understand what to do.

Also, why don't you can check the archived, solved Q&A about this specific course?


I'm pretty sure you can find the answer that you've been looking for.

Sorry if I'm not that helpful :confused: Good luck, mate!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.