You can use the following in the struct package in Python to convert:
1. byte order:
| Character |
Byte order |
Size and alignment |
| @ |
Native |
Native |
| = |
Native |
Standard |
| < |
Little-Endian |
Standard |
| > |
Big-Endian |
Standard |
| ! |
Network (= big-Endian) |
Standard |
2. number of bytes
| Format |
C type |
Python |
Notes |
| X |
Pad byte |
No value |
|
| C |
Char |
Bytes of length 1 |
|
| B |
Signed Char |
Integer |
(1) |
| B |
Unsigned Char |
Integer |
|
| ? |
_ Bool |
Bool |
(2) |
| H |
Short |
Integer |
|
| H |
Unsigned Short |
Integer |
|
| I |
Int |
Integer |
|
| I |
Unsigned Int |
Integer |
|
| L |
Long |
Integer |
|
| L |
Unsigned Long |
Integer |
|
| Q |
Long Long |
Integer |
(3) |
| Q |
Unsigned Long Long |
Integer |
(3) |
| F |
Float |
Float |
|
| D |
Double |
Float |
|
| S |
Char [] |
Bytes |
(1) |
| P |
Char [] |
Bytes |
(1) |
| P |
Void * |
Integer |
|
3. User-Defined Functions
It's quite easy to use struct
Import struct
Htonll = Lambda A: struct. Unpack ('! Q ', Struct. Pack ('Q',) ) [0] Ntohll = Lambda: Struct. Unpack ('Q ', Struct. Pack ('! Q',) ) [0]