|
-
April 12th, 2003, 03:45 PM
#1
reading double encoded by php pack() error
Hi, ive been working on porting some php code to c# and have hit an error....
the number two when encoded by the php pack() funditon to a double doesnt get read correctly by c# or im doing it wrong.
eg.
the number 1 gets packed and has the byte representation
63 240 0 0 0 0 0 0
8 byte representation.
the string that contains it contains "?ð "
i get 63 240 0 0 0 0 0 0 as the ascii codes when reading em byte by byte and typecasting to an int.
reading the 8 bytes using the BinaryReader.readDouble()
gives me 3.16202013338398E-322
BinaryReader.ReadUInt64(); gives 64
BinaryReader.ReadInt64(); gives 64
the number was encoded on a windows machine and is being read on a windows machine so the byte ordering should be the same.
the php documentation says using the "d" flag with the pack function gives a "d double (machine dependent size and representation) " the function is the same as the pack function in perl.
the number is packed using pack("d", $value) & unpacked using same flag....
1 = 63 240 0 0 0 0 0 0
2 = 64 0 0 0 0 0 0 0
3 = 64 8 0 0 0 0 0 0
4 = 64 16 0 0 0 0 0 0
i just cant seem to convert a string with those as the char code for each byte into the correct double.
any help would be great cause ive spent a week on this... ive got everything else working except for this which makes all the work ive put in useless...
if i know the algo to read and cant convert a double to the same format and that would be perfect...
is there something im not doing right?
thanks...
nik
-
April 22nd, 2003, 04:52 PM
#2
do you have a sample code ?
- Software Architect
-
April 22nd, 2003, 10:33 PM
#3
actually i figured it out... i had to reverse the binary of each char in the string, put the string back together and then using the binary version of the entire string use IEEE intepret the 64 bit double number...wat a pain.... but write a method to convert double to and fro the string version....
thanks tho..
nik
-
April 23rd, 2003, 01:24 PM
#4
good for you .
- Software Architect
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|