本文介绍了int中有多少字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我想知道是否可以控制int中的字节数和

字节顺序。在C / C ++中,我可以使用int32但是如何在

python中执行此操作?如何控制字节顺序?

Hello,
I was wondering if I could control how many bytes are in an int and
the byte order. In C/C++ I can use int32 but how do I do this in
python? How can I control byte order?

推荐答案




我怀疑你想要使用struct模块 - 但是这是一个猜测,因为你还没有真正说出你想要的是什么。

来完成。


-

格兰特爱德华兹格兰特哇!我的聚乙烯牛仔

钱包是由香港制造的

visi.com Kong by Montgomery Clift!



I suspect you want to use the "struct" module -- but it''s a
guess, since you haven''t really said what it is you''re trying
to accomplish.

--
Grant Edwards grante Yow! My polyvinyl cowboy
at wallet was made in Hong
visi.com Kong by Montgomery Clift!





你不能。 Python使用尽可能多的字节来表示

数字(更大的数字 - 更多字节)。你为什么要控制

的字节数?


问候,

马丁



You can''t. Python uses as many bytes as are necessary to represent
the number (larger numbers - more bytes). Why do you want to control
the number of bytes?

Regards,
Martin




我怀疑你想要使用struct模块 - 但它是猜测,因为你还没有真正说出你想要完成的是什么。


I suspect you want to use the "struct" module -- but it''s a
guess, since you haven''t really said what it is you''re trying
to accomplish.




我正在考虑写一个电影文件编码器(可能是avi)。所以,我需要

输出DWORD(查找显示它的4字节int)到二进制文件。

因此我需要知道这是否可以在python中完成或者不是,

会告诉我是否会尝试这样做。


但是,由于64位结构已经结束,短,长等可能会很快改变

的含义。从我在结构模块中读到的内容

docs我只能告诉它它是短暂的,长的,等等但不是否是

它''一个4字节的int。有没有办法做到这一点?



I''m thinking of writing a movie file encoder (probably avi). So, I need
to output DWORD (lookup revealed its a 4-byte int) to a binary file.
Therefore I need to know whether this can be done in python or not,
which will tell me whether I''ll try to do it or not.

But, since the 64-bit archecture is out, short, long, etc may change
there meanings quite soon. From what I''ve read in the struct module
docs I can only tell it that it''s a short, long, etc. but not whether
it''s exactly a 4-byte int. Is there a way to do this?


这篇关于int中有多少字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 18:04
查看更多