473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Python pack and unpack question

If you have the following:

data = unpack('>L', sock.recv(4))

Does this line of code means that incoming data is big endian and
unpack it to endianess of local machine? If local machine is little
endian, then big endian is automatically converted to little endian
format?

thank you.
Jul 15 '08 #1
1 3129

"joe shoemaker" <jo***********@gmail.comwrote in message
news:ma***********************************@python. org...
If you have the following:

data = unpack('>L', sock.recv(4))

Does this line of code means that incoming data is big endian and
unpack it to endianess of local machine? If local machine is little
endian, then big endian is automatically converted to little endian
format?

thank you.
Try it:
>>data = unpack('>L','\xaa\xbb\xcc\xdd')
data
(2864434397L,)
>>hex(data[0])
'0xaabbccddL'
>>data = unpack('>L','\x11\x22\x33\x44')
data
(287454020,)
>>hex(data[0])
'0x11223344'
>>>
Yes, it treats the incoming data as big-endian. The Python data type
returned varies as needed to hold the value. You'd get the same results on
a big-endian and little-endian local machine. How the Python data type is
represented internally is an implementation detail and could be anything.
--
Mark

Jul 15 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: RK | last post by:
Hi I am new to Python, find it very interesting. I was wondering if anyone has a sample source listing for an nntp newsgroup reader that they can share or will be able to point me to a...
2
by: John Hunter | last post by:
I am writing a python extension and have a question about reference counting on an attribute I set. I am using standard boilerplate code for defining a new type. I implement the setattr...
4
by: Efrat Regev | last post by:
Hello, I'd like to ask a question concerning a python script in a makefile. Suppose I have a C++ project (sorry for raising this in a Python newsgroup), with some makefile for it. Before...
4
by: Stacy Mader | last post by:
Greetings all, I have a VMS binary file with weather data. The record on each line is 1xint(8) 12xint(2) Using the perl unpack function, I can decode the binary file like this: <snip>
1
by: Shi, Jue | last post by:
Hello, Gurus, I have a question on wrapping C function in Python. My C code is like this: typedef void (WINAPI *myCallBack) (unsigned int myarg1, unsigned int myarg2) bool ...
5
by: bruce | last post by:
hi... i'm trying to deal with multi-dimension lists/arrays i'd like to define a multi-dimension string list, and then manipulate the list as i need... primarily to add lists/information to the...
23
by: neoedmund | last post by:
There's a program, it's result is "unexpected aaa", i want it to be "expected aaa". how to make it work? class C1(object): def v(self, o): return "expected "+o class C2(object):
13
by: James | last post by:
Hello, I'm a newbie to Python & wondering someone can help me with this... I have this code: -------------------------- #! /usr/bin/python import sys
5
by: tmp123 | last post by:
Hello, Thanks for your time. After review the "struct" documentation, it seems there are no option to pack/unpack zero terminated strings. By example, if the packed data contains: byte +...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.