Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-14-2008, 09:18 PM
Member
 
Join Date: Jan 2008
Posts: 8
SKaur is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-14-2008, 09:32 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
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:
Code:
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"); } } }


Another solution is found here, although doesn't look 64-bit...

Let us know your final result.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-15-2008, 03:08 AM
Member
 
Join Date: Jan 2008
Posts: 8
SKaur is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-15-2008, 08:28 PM
Member
 
Join Date: Jan 2008
Posts: 8
SKaur is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert html to text using java praveen@asia-mail.com New To Java 1 11-14-2007 03:08 PM
how to convert a Java array to a java stack? pompeez New To Java 2 08-13-2007 03:41 PM
Convert .java to .exe susan New To Java 1 07-25-2007 08:26 PM
Can't convert java.lang.String to int. Albert AWT / Swing 2 07-13-2007 06:05 PM
convert VB6 applications to Java bbq New To Java 1 07-05-2007 04:57 AM


All times are GMT +3. The time now is 08:04 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org