🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #16193

Re: Byte swapping

#16193
From: C. Callaway
Date: Tue, 16 Mar 1999 00:00
54 lines
2025 bytes
I couldn't get that to work either. Your problem is probably in that you're
trying to cast a short to an _array_ of bytes. I don't think you can cast a
single value to an array. Also I believe all values in Java are "big
endian".

Hope this helps!

Doug Bath wrote in message <36EE8AA3.3212A98D@agt.net>...
>Greetings
>
>I am trying to convert an old C++ app to java and I have hit a snag. I
>am writing a class to read seismic data in SEGY format which consists of
>short integers, long integers, and floats in IBM and IEEE format. These
>values can be in 'big endian' or 'little endian' byte order.
>In my C++ app I wrote simple byte swap routines for 2 byte or 4 byte
>values that looke like
>
>void TSegyFile::swap2(unsigned char  *str)
>/*      byte swap 16 bit integers */
>{
>    unsigned char tmp;
>
>    tmp=str[0];
>    str[0]=str[1];
>    str[1]=tmp;    //    wrote a similar function for 4 byte values
>}
>
>To call the function I cast the short integer to an unsigned char as
>
>swap2((unsigned char*)&sval);
>
>When I try to do something similar in java
>private void swap2(byte[] s)
>    {
>        byte tmp;
>
>        tmp=s[0];
>        s[0]=s[1];
>        s[1]=tmp;
>    }
>
>and call it with
>swap2((byte[]) sval);
>
>I get a message telling me I can't make such a  cast.
>
>I haven't even got to the point where I have to cast a float to a long
>int to do the IBM to IEEE conversion but I am already dreading it.
>
>Any insights would be most appreciated.
>
>
>Doug Bath
>
Technical Details
Message-ID: <7cm785$4dq26@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36EE8AA3.3212A98D@agt.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,a228e969071f0feb
X-Google-Attributes: gidf74b3,public
From: "C. Callaway" <cqcallaw@iname.com>
Subject: Re: Byte swapping
Date: 1999/03/16
Message-ID: <7cm785$4dq26@forums.borland.com>
X-Deja-AN: 455703943
References: <36EE8AA3.3212A98D@agt.net>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3155.0
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language