Results 1 to 4 of 4
- 01-14-2008, 08:18 PM #1
Member
- Join Date
- Jan 2008
- Posts
- 8
- Rep Power
- 0
How do I convert a Big-Endian(64 bit) to Little Endian(64 bit) in Java.
Hi,
How do I convert a big-endian(64 bit) to little endian(64 bit) in Java and vice versa.
For e.g. I have 40429C28F5C28F5C in big endian, I want to convert it into little endian (5C8FC2F5289C4240) and vice versa.
How would I code a function to do this in Java?
Thanks.
Sukhpreet Kaur
- 01-14-2008, 08:32 PM #2
This topic interests me as it brings me back to my Assembly programming days... check out here which may hint at a solution...
Something like the following may be helpful and was taken from here:
Java Code:[FONT=tahoma,arial,sans-serif][SIZE=-1][COLOR=#000000]import java.nio.ByteOrder; public class Endian { public static void main(String argv[]) { ByteOrder b = ByteOrder.nativeOrder(); if (b.equals(ByteOrder.BIG_ENDIAN)) { System.out.println("Big-endian"); } else { System.out.println("Little-endian"); } } } [/COLOR][/SIZE][/FONT]
Another solution is found here, although doesn't look 64-bit...
Let us know your final result.
Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
- 01-15-2008, 02:08 AM #3
Member
- Join Date
- Jan 2008
- Posts
- 8
- Rep Power
- 0
Hi CaptainMorgan,
Thank you for your help and the links you've posted.
I am looking for something Java CodeGuru: Deal with big-endian and little-endian order
but this example code is for 4-bytes, I am looking something for 8 bytes(64-bits) where I can enter (40429C28F5C28F5C) as an argument and the function can return (5C8FC2F5289C4240) ...
Any suggestions/help will be appreciated.
Thank you.
- 01-15-2008, 07:28 PM #4
Member
- Join Date
- Jan 2008
- Posts
- 8
- Rep Power
- 0
The code is shown below:
[/code]
public static long bigToLittleEndian(long bigendian) {
ByteBuffer buf = ByteBuffer.allocate(8);
buf.order(ByteOrder.BIG_ENDIAN);
buf.putLong(bigendian);
buf.order(ByteOrder.LITTLE_ENDIAN);
return buf.getLong(0);
}
public static void main(String[] args) {
long res = bigToLittleEndian(0x40429C28F5C28F5CL);
System.out.println(Long.toHexString(res));
}
[/code]
Thank you.
Similar Threads
-
Convert .java to .exe
By susan in forum New To JavaReplies: 6Last Post: 02-11-2009, 06:47 AM -
convert html to text using java
By praveen@asia-mail.com in forum New To JavaReplies: 1Last Post: 11-14-2007, 02:08 PM -
how to convert a Java array to a java stack?
By pompeez in forum New To JavaReplies: 2Last Post: 08-13-2007, 02:41 PM -
Can't convert java.lang.String to int.
By Albert in forum AWT / SwingReplies: 2Last Post: 07-13-2007, 05:05 PM -
convert VB6 applications to Java
By bbq in forum New To JavaReplies: 1Last Post: 07-05-2007, 03:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks