zoukankan      html  css  js  c++  java
  • python sturct模块操作C数据

    python中struct方便对底层数据进行操作,比如把一个数 i = 65536保存为一个4B的int型数据

    Python代码  收藏代码
    1. s0 = struct.pack("<I",i)  

       s0为一个字符串,长度为4,即占四个字节,这样方便传输与保存二进制数据。

       "<I",意思是按小端保存,>为大端,I为无符号整型。

       还有其它类型参数:

       c:char      b:signed byte                 B:unsigned byte

       h:short    H:unsigned short            i:int; I:unsigned int

       l:long       L:unsigned long              f:float

       d:double  s:string (array of char)   p: pascal string (with count byte)

       q:long long    Q:unsigned long long

       unpack用于还原数据

       假设收到s0这个字符串

    Python代码  收藏代码
    1. i2 = struct.unpack("<I",s0)  

       i2为一个元组型,i2[0]即还原的整型数字

    汇编c保护内核pe学习群: 587594855 股票价值投资套利研究群 468714081 欢迎有缘的朋友一起交流心得。
  • 相关阅读:
    day35
    Audio Unit 基础
    Audio Unit 介绍
    音频PCM编码
    iOS libyuv
    FFmpeg AVPacket
    FFmpeg AVCodec
    FFmpeg编译iOS静态库
    iOS-Cocoapods更新不及时
    iOS-读取txt文件中文乱码
  • 原文地址:https://www.cnblogs.com/myart/p/3050911.html
Copyright © 2011-2022 走看看