Article View: borland.public.jbuilder.java.language
Article #16197Re: Byte swapping
From: Doug Bath
Date: Tue, 16 Mar 1999 00:00
Date: Tue, 16 Mar 1999 00:00
36 lines
1481 bytes
1481 bytes
Steve Schafer (TeamB) wrote:
> Here's a
> general approach:
>
Thanks Steve,
You're right, I am being to pessimistic. I can get the following to compile but
when I run it I get a zillion error messages which blast by too fast to read. I am
using jdk1.2 with a text editor.
private short swap2(short s)
{
byte tmp;
byte[] b=new byte[2];
ByteArrayOutputStream ostrm=new ByteArrayOutputStream(2);
b=ostrm.toByteArray();
ostrm.write(s);
tmp=b[0];
b[0]=b[1];
b[1]=tmp;
ByteArrayInputStream istrm=new ByteArrayInputStream(b);
return (short)istrm.read();
}
I suspect the return is the problem since read only returns 1 byte and I want 2.
the method readShort would be useful here.
Any suggestions would be most appreciated and thanks again.
Doug Bath
Technical Details
Message-ID:
<36EEE268.A4E8AA6C@agt.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<36EE8AA3.3212A98D@agt.net> <7cm785$4dq26@forums.borland.com> <36EEAA63.C25717AC@agt.net> <3779b5bb.478259775@90.0.0.40>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,a228e969071f0feb X-Google-Attributes: gidf74b3,public From: Doug Bath <dbath@agt.net> Subject: Re: Byte swapping Date: 1999/03/16 Message-ID: <36EEE268.A4E8AA6C@agt.net> X-Deja-AN: 455828494 Content-Transfer-Encoding: 7bit References: <36EE8AA3.3212A98D@agt.net> <7cm785$4dq26@forums.borland.com> <36EEAA63.C25717AC@agt.net> <3779b5bb.478259775@90.0.0.40> Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language