FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithms-python/algorithms/bit/reverse_bits.py at master · ivan1911/algorithms-python · GitHub
ivan1911
/
algorithms-python
Public
forked from
keon/algorithms
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithms-python
/
algorithms
/
bit
/
reverse_bits.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
16 lines (15 loc) · 366 Bytes
Breadcrumbs
algorithms-python
/
algorithms
/
bit
/
reverse_bits.py
Copy path
File metadata and controls
16 lines (15 loc) · 366 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
"""
Reverse bits of a given 32 bits unsigned integer.
For example, given input 43261596
(represented in binary as 00000010100101000001111010011100),
return 964176192
(represented in binary as 00111001011110000010100101000000).
"""
def
reverse_bits
(
n
):
m
=
0
i
=
0
while
i
<
32
:
m
=
(
m
<<
1
)
+
(
n
&
1
)
n
>>=
1
i
+=
1
return
m
Back
|
FazBrowse Home
|
New Git URL