FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithms-python/algorithms/bit/bytes_int_conversion.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
/
bytes_int_conversion.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (27 loc) · 652 Bytes
Breadcrumbs
algorithms-python
/
algorithms
/
bit
/
bytes_int_conversion.py
Copy path
File metadata and controls
35 lines (27 loc) · 652 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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from
collections
import
deque
def
int_to_bytes_big_endian
(
num
):
bytestr
=
deque
()
while
num
>
0
:
# list.insert(0, ...) is inefficient
bytestr
.
appendleft
(
num
&
0xff
)
num
>>=
8
return
bytes
(
bytestr
)
def
int_to_bytes_little_endian
(
num
):
bytestr
=
[]
while
num
>
0
:
bytestr
.
append
(
num
&
0xff
)
num
>>=
8
return
bytes
(
bytestr
)
def
bytes_big_endian_to_int
(
bytestr
):
num
=
0
for
b
in
bytestr
:
num
<<=
8
num
+=
b
return
num
def
bytes_little_endian_to_int
(
bytestr
):
num
=
0
e
=
0
for
b
in
bytestr
:
num
+=
b
<<
e
e
+=
8
return
num
Back
|
FazBrowse Home
|
New Git URL