msg00981.html

1998Q3/msg00981.html · 8.6 KB

From the archive 1998Q3.zip

Download the archive   « Back to the archive contents

<!-- MHonArc v2.4.4 -->
<!--X-Subject: [MUD&#45;Dev] Re: [CODE QUESTION] How to encode floats into bytes? -->
<!--X-From-R13: Pra Uerrne <terrneNploreuvtujnl.arg> -->
<!--X-Date: Mon, 7 Sep 1998 10:43:39 &#45;0700 -->
<!--X-Message-Id: Pine.LNX.3.96.980907103219.32349A&#45;100000#shamen,cyberhighway.net -->
<!--X-Content-Type: text/plain -->
<!--X-Reference: 19980907120557.A21342#yuma,Princeton.EDU -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, [MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:greear#cyberhighway,net">
</head>
<body background="/backgrounds/paperback.gif" bgcolor="#ffffff"
      text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000">

  <font size="+4" color="#804040">
    <strong><em>MUD-Dev<br>mailing list archive</em></strong>
  </font>
      
<br>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
<br clear=all><hr>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->

Date:&nbsp;
[&nbsp;<a href="msg00980.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00982.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00979.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00984.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00981">Author</A>
&nbsp;|&nbsp;<A HREF="#00981">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00981">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
<LI><em>Subject</em>: [MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</LI>
<LI><em>From</em>: Ben Greear &lt;<A HREF="mailto:greear#cyberhighway,net">greear#cyberhighway,net</A>&gt;</LI>
<LI><em>Date</em>: Mon, 7 Sep 1998 10:40:57 -0700 (MST)</LI>
<LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>

On Mon, 7 Sep 1998, Adam J. Thornton wrote:

&gt; On Mon, Sep 07, 1998 at 07:52:41AM -0600, T. Alexander Popiel wrote:
&gt; &gt; In message:  &lt;<A HREF="msg00976.html">Pine.LNX.3.96.980906215952.30075A-100000#shamen,cyberhighway.net</A>&gt;
&gt; &gt; &gt;What is the standard way (if there is one) to encode floating
&gt; &gt; &gt;point numbers (double too I guess) into bytes for transport accross
&gt; &gt; &gt;the network.
&gt; &gt; &gt;It would seem like there would be a method to do this somewhere!
&gt; &gt; Standard is to send raw IEEE format across the wire; just about
&gt; &gt; everyone uses IEEE internally these days, and those who don't
&gt; &gt; know how to convert, so they can talk with those that do.
&gt; 
&gt; You'd clearly use htonl() for ints.  You could use fcvt() or ecvt().  Or
&gt; maybe even sprintf().  All of these are probably a little more portable, but
&gt; much slower, and when you're recovering the number with sscanf() you need
&gt; to worry about precision.

I'm perfectly happy sending bits across in IEEE 754 format.  However,
I don't know how to get the bits.  Can you bit-mask floats?  Basically,
I need a way to grab the mantissa and the exponent as either raw bits
or integers.  Then I can pack it according to the IEEE standard.

Maybe I'm being too complicated. Maybe something like this would encode:

file_descriptor f;  //assume it's connected appropriately.
float f = 42.5;
char* bytes = (char*)(&amp;f);
write(f, bytes, 0, 4);      //think those args are right..

This ignores network order, but I can deal with that.

Ben
&gt; 
&gt; Adam
&gt; -- 
&gt; adam#princeton,edu 
&gt; "There's a border to somewhere waiting, and a tank full of time." - J. Steinman
&gt; 
&gt; -- 
&gt; MUD-Dev: Advancing an unrealised future.
&gt; 


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




</PRE>

<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<HR>
<ul compact><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><A NAME="00991" HREF="msg00991.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></strong>
<ul compact><li><em>From:</em> Adam Wiggins &lt;adam#angel,com&gt;</li></ul>
<li><strong><A NAME="00985" HREF="msg00985.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></strong>
<ul compact><li><em>From:</em> "Ola Fosheim Grøstad" &lt;olag#ifi,uio.no&gt;</li></ul>
<li><strong><A NAME="00984" HREF="msg00984.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></strong>
<ul compact><li><em>From:</em> Richard Woolcock &lt;KaVir#dial,pipex.com&gt;</li></ul>
</UL></LI></UL>
<!--X-Follow-Ups-End-->
<!--X-References-->
<UL><LI><STRONG>References</STRONG>:
<UL>
<LI><STRONG><A NAME="00979" HREF="msg00979.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></STRONG>
<UL><LI><EM>From:</EM> "Adam J. Thornton" &lt;adam#phoenix,Princeton.EDU&gt;</LI></UL></LI>
</UL></LI></UL>
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00980.html">[MUD-Dev] Monthly FAQ Posting</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00982.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00979.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00984.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00981"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00981"><STRONG>Thread</STRONG></A></LI>
</UL>
</LI>
</UL>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
<ul><li>Thread context:
<BLOCKQUOTE><UL>
<LI><strong><A NAME="00992" HREF="msg00992.html">[MUD-Dev] Adventure on the web</A></strong>, 
J C Lawrence <a href="mailto:claw#under,engr.sgi.com">claw#under,engr.sgi.com</a>, Tue 08 Sep 1998, 21:01 GMT
<LI><strong><A NAME="00976" HREF="msg00976.html">[MUD-Dev] [CODE QUESTION]  How to encode floats into bytes?</A></strong>, 
Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Mon 07 Sep 1998, 05:09 GMT
<UL>
<LI><strong><A NAME="00978" HREF="msg00978.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></strong>, 
T. Alexander Popiel <a href="mailto:popiel#snugharbor,com">popiel#snugharbor,com</a>, Mon 07 Sep 1998, 14:53 GMT
<UL>
<LI><strong><A NAME="00979" HREF="msg00979.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></strong>, 
Adam J. Thornton <a href="mailto:adam#phoenix,Princeton.EDU">adam#phoenix,Princeton.EDU</a>, Mon 07 Sep 1998, 16:06 GMT
<UL>
<LI><strong><A NAME="00981" HREF="msg00981.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></strong>, 
Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Mon 07 Sep 1998, 17:43 GMT
<UL>
<LI><strong><A NAME="00984" HREF="msg00984.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></strong>, 
Richard Woolcock <a href="mailto:KaVir#dial,pipex.com">KaVir#dial,pipex.com</a>, Mon 07 Sep 1998, 18:07 GMT
</LI>
<LI><strong><A NAME="00985" HREF="msg00985.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></strong>, 
Ola Fosheim Grøstad <a href="mailto:olag#ifi,uio.no">olag#ifi,uio.no</a>, Mon 07 Sep 1998, 20:44 GMT
<UL>
<LI><strong><A NAME="00986" HREF="msg00986.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></strong>, 
Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Mon 07 Sep 1998, 21:41 GMT
<UL>
<LI><strong><A NAME="00987" HREF="msg00987.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></strong>, 
T. Alexander Popiel <a href="mailto:popiel#snugharbor,com">popiel#snugharbor,com</a>, Mon 07 Sep 1998, 22:44 GMT
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL></BLOCKQUOTE>

</ul>
<hr>
<center>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
</center>
<hr>
</body>
</html>

Site Stats

Snippets: 1791
Codebases: 571