[Home] [Groups] - Message: [Prev in Group] [Next in Group]

nu.kanga.list.mud-dev

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

[Full Header] [Plain Text]
From: "T. Alexander Popiel" <popiel@snugharbor.com>
Newsgroups: nu.kanga.list.mud-dev
Date: Mon, 07 Sep 1998 07:52:41 -0600
References: [1]
Organization: Kanga.Nu
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).

- Alex