由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - python question, easy one
相关主题
请教一道C语言的题目serialization 到底该怎么理解啊?
关于 big/little endian,为什么对char 有影响?java真是让人纠结
弱人再问一个关于Java的问题BigEndian和LittleEndian的设计
Intel为什么选用little endian? (转载)C的左移和右移是否受BigEndian和LittleEndian的影响?
有没有现成的模拟fread的bufferRead()?几道面试题:memory, sort, 等
little endian vs big endian谁帮我解释一下这个代码
来来来,我也问个题 (转载)【请教】在Solaris下开发和Linux开发有什么不同? (转载)
Java questionc++如何把小数转成二进制输出到文本文件?
相关话题的讨论汇总
话题: python话题: unsigned话题: bytes话题: were话题: data
进入Programming版参与讨论
1 (共1页)
l*****r
发帖数: 15615
1
in a communication task, the python script received the data buff as a list
of bytes.
since python tool was used to do the communication with embedded software,
which were written in C/C++;
so the message were definded in c as type of structure, for example
struct
{
unsigned long variable1;
unsigned char variable2;
unsigned char variable3[4];
...
}MessageType
in stead of writing a function in python to decode the message buffer byte
by byte: forming four bytes into unsigned long/int; and etc.
is there a better approach for this?
j*a
发帖数: 14423
2
http://docs.python.org/py3k/library/index.html
6.3. struct — Interpret bytes as packed binary data

list

【在 l*****r 的大作中提到】
: in a communication task, the python script received the data buff as a list
: of bytes.
: since python tool was used to do the communication with embedded software,
: which were written in C/C++;
: so the message were definded in c as type of structure, for example
: struct
: {
: unsigned long variable1;
: unsigned char variable2;
: unsigned char variable3[4];

l*****r
发帖数: 15615
3
how does that gonna help?
I already have the data in bytes in a list.
let us say the data is like
abc = [ ,,,,,0x54, 0xA1, 0xB2, 0x3F]
and the last 4 bytes of the data is a number as: 0x3FB2A154, since they were
in little Endian. how does struct can help in this case.
Thanks for your reply.

【在 j*a 的大作中提到】
: http://docs.python.org/py3k/library/index.html
: 6.3. struct — Interpret bytes as packed binary data
:
: list

j*a
发帖数: 14423
4
http://docs.python.org/py3k/library/struct.html#examples

were

【在 l*****r 的大作中提到】
: how does that gonna help?
: I already have the data in bytes in a list.
: let us say the data is like
: abc = [ ,,,,,0x54, 0xA1, 0xB2, 0x3F]
: and the last 4 bytes of the data is a number as: 0x3FB2A154, since they were
: in little Endian. how does struct can help in this case.
: Thanks for your reply.

l*****r
发帖数: 15615
5
apperantly, I am not that smart as you. and don't see how examples helps me.

【在 j*a 的大作中提到】
: http://docs.python.org/py3k/library/struct.html#examples
:
: were

l*****r
发帖数: 15615
6
well, you could explain better just saying somthing like
pack the list into binary then unpack them;
but throwing out web links, didn't really help.
and you have more WB than me, so I guess you will be fine if I don't pay you
any.

【在 j*a 的大作中提到】
: http://docs.python.org/py3k/library/struct.html#examples
:
: were

j*a
发帖数: 14423
7
that's cool

you

【在 l*****r 的大作中提到】
: well, you could explain better just saying somthing like
: pack the list into binary then unpack them;
: but throwing out web links, didn't really help.
: and you have more WB than me, so I guess you will be fine if I don't pay you
: any.

1 (共1页)
进入Programming版参与讨论
相关主题
c++如何把小数转成二进制输出到文本文件?有没有现成的模拟fread的bufferRead()?
fread/fwrite有big/small endian问题吗?little endian vs big endian
template specialization来来来,我也问个题 (转载)
大牛讲讲JIT和AOT的比较吧Java question
请教一道C语言的题目serialization 到底该怎么理解啊?
关于 big/little endian,为什么对char 有影响?java真是让人纠结
弱人再问一个关于Java的问题BigEndian和LittleEndian的设计
Intel为什么选用little endian? (转载)C的左移和右移是否受BigEndian和LittleEndian的影响?
相关话题的讨论汇总
话题: python话题: unsigned话题: bytes话题: were话题: data