Splitting a float into bytes:

2006-07-26 Thread Michael Yanowitz
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

Re: Splitting a float into bytes:

2006-07-26 Thread Simon Forman
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 =

RE: Splitting a float into bytes:

2006-07-26 Thread Michael Yanowitz
-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

Re: Splitting a float into bytes:

2006-07-26 Thread spartacus
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

Re: Splitting a float into bytes:

2006-07-26 Thread Simon Forman
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

Re: Splitting a float into bytes:

2006-07-26 Thread John Machin
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 =