Article View: borland.public.jbuilder.java.language
Article #314Big Indian format to Windows format real
From: Kent
Date: Thu, 13 Oct 2005 20:29
Date: Thu, 13 Oct 2005 20:29
52 lines
2277 bytes
2277 bytes
I have an application written in Delphi that I am porting to
Java. In the delphi program I read in some real values in
BigEndian format. I then convert these to Windows real format
by using a variant record, which Java doesn't have, to swap
bytes so that the proper format can be obtained.
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.
type
realvar = record // Note use of variant record which Java does not have.
case RealNum:byte of
1:(bytename: byte4);
2:(realname: single);
end;
WordVar = record
case WordNum:byte of
1:(ByteName: Byte2);
2:(WordName: Word);
end;
// procedures
function TSDIAppForm.Convert(ByteArray:single):single;
var
temp : realvar;
begin
temp.realname := ByteArray;
swap(temp.bytename[1], temp.bytename[4]);
swap(temp.bytename[2], temp.bytename[3]);
try
begin
if temp.realname < 0 then
Convert := 0
else
Convert := temp.realname;
end
except
on EInvalidOp do
Convert := 0;
end;
end; { of Convert }
function TSDIAppForm.ConvertWord(Value : Word):Word;
var
Temp : Wordvar;
begin
Temp.wordName := Value;
Swap(temp.ByteName[1], Temp.ByteName[2]);
ConvertWord := Temp.WordName;
end; { of ConvertWord }
Technical Details
Message-ID:
<434ec3ae$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newshub.sdsu.edu!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!pd7cy1no!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: f74b3,8a96fd610a68e12d,start X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Kent" <Kent.White@att.net> Sender: "Kent" <Kent.White@att.net> Reply-To: "Kent" <Kent.White@att.net> Subject: Big Indian format to Windows format real Newsgroups: borland.public.jbuilder.java.language X-User-Info: 209.33.31.12 NNTP-Posting-Host: 207.105.83.66 Message-ID: <434ec3ae$1@newsgroups.borland.com> Date: 13 Oct 2005 13:29:34 -0700 X-Trace: newsgroups.borland.com 1129235374 207.105.83.66 (13 Oct 2005 13:29:34 -0700) Lines: 53 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newshub.sdsu.edu!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!pd7cy1no!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail