msg00985.html
1998Q3/msg00985.html · 7.2 KB
From the archive 1998Q3.zip
Download the archive « Back to the archive contents
<!-- MHonArc v2.4.4 -->
<!--X-Subject: [MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes? -->
<!--X-From-R13: "Ayn Tbfurvz Ueøfgnq" <byntNvsv.hvb.ab> -->
<!--X-Date: Mon, 7 Sep 1998 13:44:48 -0700 -->
<!--X-Message-Id: 35F44429.93791B54#ifi,uio.no -->
<!--X-Content-Type: text/plain -->
<!--X-Reference: Pine.LNX.3.96.980907103219.32349A-100000#shamen,cyberhighway.net -->
<!--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:olag#ifi,uio.no">
</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>
[ <a href="../">Other Periods</a>
| <a href="../../">Other mailing lists</a>
| <a href="/search.php3">Search</a>
]
<br clear=all><hr>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->
Date:
[ <a href="msg00984.html">Previous</a>
| <a href="msg00986.html">Next</a>
]
Thread:
[ <a href="msg00984.html">Previous</a>
| <a href="msg00986.html">Next</a>
]
Index:
[ <A HREF="author.html#00985">Author</A>
| <A HREF="#00985">Date</A>
| <A HREF="thread.html#00985">Thread</A>
]
<!--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>: "Ola Fosheim Grøstad" <<A HREF="mailto:olag#ifi,uio.no">olag#ifi,uio.no</A>></LI>
<LI><em>Date</em>: Mon, 07 Sep 1998 22:38:01 +0200</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>
Ben Greear wrote:
>
>
> Maybe I'm being too complicated. Maybe something like this would encode:
Yeah.
> file_descriptor f; //assume it's connected appropriately.
> float f = 42.5;
> char* bytes = (char*)(&f);
> write(f, bytes, 0, 4); //think those args are right..
>
> This ignores network order, but I can deal with that.
(but your compiler can't deal with multiple f variables :^)
typedef unsigned long uint32;
typedef unsigned char uint8;
assert(sizeof(float)==4);
assert(sizeof(uint32)==4);
assert(char is 8 bit);
assert(floats use same endianess as ints);
void conv(const float f,uint8 *dst){
const uint32 i = *((uint32 *)(void *)&f);
dst[0] = (uint8)((i>>24)&0xff);
dst[1] = (uint8)((i>>16)&0xff);
dst[2] = (uint8)((i>>8)&0xff);
dst[3] = (uint8)((i)&0xff);
}
Does Java provide functions for converting floats to raw bytes?
--
Ola Fosheim Groestad,Norway
</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="00986" HREF="msg00986.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></strong>
<ul compact><li><em>From:</em> Ben Greear <greear#cyberhighway,net></li></ul>
</UL></LI></UL>
<!--X-Follow-Ups-End-->
<!--X-References-->
<UL><LI><STRONG>References</STRONG>:
<UL>
<LI><STRONG><A NAME="00981" HREF="msg00981.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></STRONG>
<UL><LI><EM>From:</EM> Ben Greear <greear#cyberhighway,net></LI></UL></LI>
</UL></LI></UL>
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00984.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00986.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00984.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00986.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00985"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00985"><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>[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</STRONG>, <EM>(continued)</EM>
<ul compact>
<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>
<LI><strong><A NAME="00991" HREF="msg00991.html">[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?</A></strong>,
Adam Wiggins <a href="mailto:adam#angel,com">adam#angel,com</a>, Tue 08 Sep 1998, 19:26 GMT
<UL>
<LI><strong><A NAME="00995" HREF="msg00995.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>, Wed 09 Sep 1998, 19:14 GMT
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</ul>
</LI>
</UL></BLOCKQUOTE>
</ul>
<hr>
<center>
[ <a href="../">Other Periods</a>
| <a href="../../">Other mailing lists</a>
| <a href="/search.php3">Search</a>
]
</center>
<hr>
</body>
</html>