Implementation of Python-ntohll and htonll

Source: Internet
Author: User
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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.