Saturday, June 23, 2018

Python: Bit-wise Swap Function



Bit-wise Swap Function

Apart from Python binary functions (<< , >> , ^) I noticed I need bit-wise swap function too, It is simple but useful. The Idea is swapping specified bit in binary format of an integer number, if it is 1 turns into 0 and vice versa.
The Functions counts bit positions from right to left and first bit is considered as 1. No error handling implemented.
In the figure you can see the function definition and the sample output as comments.
Enjoy :)


No comments:

Post a Comment

Format

Here is all you need to know about string formatting. I have summarized the page  https://pyformat.info/  , in fact I just removed all e...