MUD-Dev
mailing list archive

[ Other Periods  | Other mailing lists  | Search  ]

Date:  [ Previous  | Next  ]      Thread:  [ Previous  | Next  ]      Index:  [ Author  | Date  | Thread  ]

[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?




On Mon, 7 Sep 1998, T. Alexander Popiel wrote:

> In message:  <Pine.LNX.3.96.980906215952.30075A-100000#shamen,cyberhighway.net>
>              Ben Greear <greear#cyberhighway,net> writes:
> >
> >What is the standard way (if there is one) to encode floating
> >point numbers (double too I guess) into bytes for transport accross
> >the network.
> >
> >I'm using c++, on both ends (encode/decode).
> >
> >It would seem like there would be a method to do this somewhere!
> 
> Standard is to send raw IEEE format across the wire; just about
> everyone uses IEEE internally these days, and those who don't
> know how to convert, so they can talk with those that do.
> 
> IEEE 32-bit format is bigendian: 1 sign bit, 8 bits exponent in
> offset 127 notation, implied 1 (not stored), 23 bits mantissa.
> Special codes are used in the exponent to denote NaN, +/-Inf,
> and reduced-precision numbers between 2^-128 and 2^-152.
> 
> IEEE 64-bit is similar, with 16 bits exponent and 47 bits
> mantissa.
> 
> If you do the conversion manually, actually check the standard;
> I prolly have an off-by-one error in the above (which was taken
> from memory).

I was looking at the standard last night..  You are at least
very close :)  (Don't remember all the details myself.)

I'm going to play around with bit-masking and casting to see if
I can get at the bits w/out turning the target into an integer!

Thanks,
Ben

> 
> - Alex
> 
> -- 
> MUD-Dev: Advancing an unrealised future.
> 


Ben Greear (greear#cyberhighway,net)  http://www.primenet.com/~greear 
Author of ScryMUD:  mud.primenet.com 4444
http://www.primenet.com/~greear/ScryMUD/scry.html






[ Other Periods  | Other mailing lists  | Search  ]