Hello:
For some reason I can't figure out how to split
a 4-byte (for instance) float number (such as 3.14159265359)
into its 4-bytes so I can send it via a socket to another
computer.
For integers, it is easy, I can get the 4 bytes by anding like:
byte1 = int_val 0x00FF
byte2 = int_val
Michael Yanowitz wrote:
Hello:
For some reason I can't figure out how to split
a 4-byte (for instance) float number (such as 3.14159265359)
into its 4-bytes so I can send it via a socket to another
computer.
For integers, it is easy, I can get the 4 bytes by anding like:
byte1 =
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf
Of Simon Forman
Sent: Wednesday, July 26, 2006 2:56 PM
To: python-list@python.org
Subject: Re: Splitting a float into bytes:
Michael Yanowitz wrote:
Hello:
For some reason I can't figure out how to split
Yes i think you can. If you use the struct module.
import struct
import math
y = struct.pack('!f', math.pi)
print repr(y)
'@I\x0f\xdb'
Michael Yanowitz [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Hello:
For some reason I can't figure out how to split
a 4-byte (for
Michael Yanowitz wrote:
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf
Of Simon Forman
Sent: Wednesday, July 26, 2006 2:56 PM
To: python-list@python.org
Subject: Re: Splitting a float into bytes:
Michael Yanowitz wrote:
Hello:
For some reason
Michael Yanowitz wrote:
Hello:
For some reason I can't figure out how to split
a 4-byte (for instance) float number (such as 3.14159265359)
into its 4-bytes so I can send it via a socket to another
computer.
For integers, it is easy, I can get the 4 bytes by anding like:
byte1 =