SMZE wrote: > Posso anche aver frainteso come funzioni unpack() perchè ad esempio: > > >>> struct.unpack('>BBBBB','\x03\xff\x55\xa6\x00') > (3, 255, 85, 166, 0) > > >>> struct.unpack('<BBBBB','\x03\xff\x55\xa6\x00') > (3, 255, 85, 166, 0) > > per la prima istruzione tutto ok. Ma come mai la seconda mi mantiene gli > stessi valori?
La differenza tra le due format string è il byte order, big endian nella prima, little endian nella seconda. Il concetto di byte order si applica a tipi di dati multibyte: tu invece sopra hai specificato "B", cioé "unsigned char". In C, questo tipo è costituito da *un* byte: essendo uno solo non può essere ordinato. :-) Il byte order si applica a tipi multibyte, come ad esempio gli "unsigned long": >>> struct.unpack('>L','\x03\xff\x55\xa6') (67065254L,) >>> struct.unpack('<L','\x03\xff\x55\xa6') (2790653699L,) -- Nicola Larosa - http://www.tekNico.net/ Legally or otherwise, domestically or from overseas, flawless copies can and will be obtained. And the modern European pirates who retrieve and share our cultural gold - gold that the owners had forsaken - are not scoundrels who defy the law but heroes who advance its ultimate aim. -- Peter Guttman, July 2006
_______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python