Thread: "A little bit of Java, all night long"...

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273

    Red face "A little bit of Java, all night long"...

    Hello,

    Recently I've been toying with Java, assessing it largely by porting some of my C programs to it. However, I've now ran into a little problem, and no matter how many showers I take, I can't get Java off me(!).

    I tried to port a program that deals with Wave files. Of course, all of the multi-byte numbers in it are little endian, but Java's big endian. Fearing that I may be stuck with a little endian for the rest of my life, I tried constructing this function inside my main class:-
    Code:
    public static int reverseInt(int source)
    {
    	int dest;
    
    	dest = ((source & 0xFF000000) >> 24) | ((source & 0xFF0000) >> 8) | ((source & 0xFF00) << 8) | ((source & 0xFF) << 24);
    	return dest;
    }
    This seems to work for all but certain numbers, I get strange results sometimes. As I haven't reinstalled my C compiler yet, I can't wallow in the safety of familiarity, so would anyone care to offer assistance?

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Have you tried:
    Code:
    	dest = ((source & 0xFF000000) >>> 24) | ((source & 0xFF0000) >>> 8) | ((source & 0xFF00) << 8) | ((source & 0xFF) << 24);

  3. #3
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Perfect, swoopy. Didn't know about that operator (>>>).

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    SMurf, glad it works. I saw a list of operators at the link below, and thought it was worth trying.

    Operators

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copy bit to bit
    By Coder2Die4 in forum C Programming
    Replies: 15
    Last Post: 06-26-2003, 09:58 AM
  2. binary numbers
    By watshamacalit in forum C Programming
    Replies: 4
    Last Post: 01-14-2003, 11:06 PM
  3. Analysis of Top Programming Languages Companies Need :: Inbelievable!
    By kuphryn in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 01-06-2003, 04:23 PM
  4. 16 bit or 32 bit
    By Juganoo in forum C Programming
    Replies: 9
    Last Post: 12-19-2002, 07:24 AM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM