Article View: borland.public.jbuilder.java.language
Article #316Re: Big Indian format to Windows format real
From: Gillmer J. Derge [TeamB]
Date: Fri, 14 Oct 2005 04:07
Date: Fri, 14 Oct 2005 04:07
20 lines
1683 bytes
1683 bytes
Kent wrote:
> How do I accomplish the same task in Java? Below is the code
> that swaps the proper bytes to get the value in the proper
> format.
Read the values as 4 bytes, turn them into an int, then use
Float.intBitsToFloat. Something like this (uncompiled and untested, but
if you treat it as pseudocode, it should more or less work).
float readBigEndianFloat(InputStream in) throws IOException {
DataInputStream dataIn = new DataInputStream(in);
byte[] bytes = new byte[4];
dataIn.readFully(bytes);
int i = (byte[3] << 24) | (byte[2] << 16) | (byte[1] << 8) |
byte[0];
return Float.intBitsToFloat(i);
}
--
Gillmer J. Derge [TeamB]
Technical Details
Message-ID:
<434f2e51$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<434ec3ae$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,8a96fd610a68e12d X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Fri, 14 Oct 2005 00:07:19 -0400 From: "Gillmer J. Derge [TeamB]" <spam@gillmerderge.com> User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language Subject: Re: Big Indian format to Windows format real References: <434ec3ae$1@newsgroups.borland.com> In-Reply-To: <434ec3ae$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.149.56.207 Message-ID: <434f2e51$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1129262673 24.149.56.207 (13 Oct 2005 21:04:33 -0700) Lines: 20 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail