🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Byte swapping

#16192
From: Doug Bath
Date: Tue, 16 Mar 1999 00:00
45 lines
1649 bytes
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: <36EE8AA3.3212A98D@agt.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,a228e969071f0feb,start
X-Google-Attributes: gidf74b3,public
From: Doug Bath <dbath@agt.net>
Subject: Byte swapping
Date: 1999/03/16
Message-ID: <36EE8AA3.3212A98D@agt.net>
X-Deja-AN: 455675274
Content-Transfer-Encoding: 7bit
Organization: Another Netscape Collabra Server User
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language