Article View: borland.public.jbuilder.java.language
Article #16198Re: Byte swapping
From: Doug Bath
Date: Tue, 16 Mar 1999 00:00
Date: Tue, 16 Mar 1999 00:00
30 lines
1246 bytes
1246 bytes
Chris Hill wrote:
> You need to do it differently in Java.
>
Thanks Chris
I got your method to work by casting each line to a short.
private short swap2(short s)
{
short tmp1, tmp2;
tmp1 = (short)((s & 0xFF) << 8);
tmp2 = (short)((s >> 8) & 0xFF);
return (short)(tmp1 | tmp2);
}
This works fine but I am ashamed to admit I am very shaky on bit shifting so
I am not sure how to get the 4 byte version to work. I am going to re-read my
K & R tonight. I am also going to pursue Steve's approach for 4 byte swaps
which, although I haven't got it to work yet, I at least can get my head
around it.
Again Many thanks
Doug Bath
Technical Details
Message-ID:
<36EEE3CA.F6F4D6A3@agt.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<36EE8AA3.3212A98D@agt.net> <36eeb7cc.66297370@forums.borland.com>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: <36EEE3CA.F6F4D6A3@agt.net> X-Deja-AN: 455834311 Content-Transfer-Encoding: 7bit References: <36EE8AA3.3212A98D@agt.net> <36eeb7cc.66297370@forums.borland.com> Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language