Programming to fight in the world ~ 5-5,5-6

bit.py



class Bitutils():
    def bitSwapRequired(self,a,b):
        count = 0
        c = a ^ b
        while c != 0:
            if c and 1 != 0:
                count += 1
            c >>= 1
        return count
    
    def swapOddEvenBits(self,x):
        even =  (x & 0b10101010 >> 1)
        odd = (x & 0b01010101 << 1)
        return even or odd

A function that swaps even and odd bits It's easy to do

Recommended Posts

Programming to fight in the world ~ 5-1
Programming to fight in the world ~ 5-5,5-6
Programming to fight in the world 5-3
Programming to fight in the world ~ 5-2
Programming to fight in the world-Chapter 4
"Book to train programming skills to fight in the world" Python code answer example --1.3 URLify
"Book to train programming skills to fight in the world" Python code answer example --2.6 palindrome
"Book to train programming skills to fight in the world" Python code answer example --2.4 Splitting the list
"Book to train programming skills to fight in the world" Python code answer example --2.7 intersecting nodes
"A book to train programming skills to fight in the world" Python code answer example --1.8 "0" matrix
"A book to train programming skills to fight in the world" Python code Solution example --1.6 String compression
"A book to train programming skills to fight in the world" Python code solution example --1.5 One-shot conversion
"A book to train programming skills to fight in the world" Python code answer example --3.1 Three stacks
"A book to train programming skills to fight in the world" Python code Solution example --1.7 Matrix rotation
"Book to train programming skills to fight in the world" Python code answer example --1.4 Permutation of sentences
"A book to train programming skills to fight in the world" Python code Solution example --2.8 Loop detection
Programming language in "Hello World"
"Book to train programming skills to fight in the world" Python code solution example --- Removed elements between 2.3
"Book to train programming skills to fight in the world" Python code Solution example --2.1 Remove duplicate elements
The easiest line bot in the world to lose weight
"A book to train programming skills to fight in the world" Python code answer example --1.9 Rotation of strings
"A book to train programming skills to fight in the world" Python code answer example --1.1 Duplicate character string
Activity record in the programming circle
In the python command python points to python3.8
The most cited patent in the world
"A book to train programming skills to fight in the world" Python code answer example --2.2 Returns the Kth from the back
Cython to try in the shortest
"A book to train programming skills to fight in the world" Python code answer example --1.2 Count the number of the same characters
Hit the echo command in the Mac terminal to output Hello World
I want to know the population of each country in the world.
The most sought after programming language in 2020
"A book to train programming skills to fight in the world" Python code Solution example --2.5 The sum of two numbers shown in the list
In Jupyter, add IPerl to the kernel.
Draw graphs in the programming language Julia
Various comments to write in the program
How to display Hello world in python
Guidelines for reincarnating in the world of linux programming development (C / C ++ language)
Programming in python
How to use the C library in Python
Log in to the remote server with SSH
Twitter streaming client to enjoy in the terminal
To dynamically replace the next method in python
Say hello to the world with Python with IntelliJ
Draw graphs in Julia ... Leave the graphs to Python
The trick to write flatten concisely in python
How to get the files in the [Python] folder
Use pygogo to get the log in json.
I want to display the progress in Python!
How to retrieve the nth largest value in Python
I tried to graph the packages installed in Python
How to get the variable name itself in python
Try to solve the programming challenge book with python3
How to run the Ansible module added in Ansible Tower
The easiest way to set up Last-Modified in Flask
Add auto-completion to EV3 Micropyhon programming in VS Code
How to get the number of digits in Python
The story of building the fastest Linux environment in the world
How to know the current directory in Python in Blender
If there were no DI containers in the world.
Convert the image in .zip to PDF with Python
Set the form DateField to type = date in Django