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

T. Alexander Popiel popiel at snugharbor.com
Mon Sep 7 07:52:41 CEST 1998


In message:  <Pine.LNX.3.96.980906215952.30075A-100000 at shamen.cyberhighway.net>
             Ben Greear <greear at 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




More information about the mud-dev-archive mailing list