943,614 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3227
  • Java RSS
Dec 16th, 2008
0

about big endian and little endian representation

Expand Post »
i want to write a code for big endian and little endian represntation of message.The msg is trading message.How can i do it with core java?

also how can i check data type validity of input given by user and data type is also provided by user.
Both Data type ind value i m asking to the user.& i wznt to check that whether user has entered correct value?
Similar Threads
Reputation Points: 9
Solved Threads: 0
Light Poster
srs_grp is offline Offline
34 posts
since Sep 2008
Dec 16th, 2008
0

Re: about big endian and little endian representation

This will keep you very busy for a while........... :-)

1. Big endian machine: Stores data big-end first. When looking at multiple bytes, the first byte (lowest address) is the biggest.
Motorola processors are this kind hardware.
Unix
2. Little endian machine: Stores data little-end first. When looking at multiple bytes, the first byte is smallest.
Intel processors are this kind hardware.
Windowsx

Do you need to convert little-E to big-E ?
What is your message is made of text only or number & text ?




Albert
Reputation Points: 9
Solved Threads: 2
Light Poster
AlbertPi is offline Offline
33 posts
since Nov 2008
Dec 16th, 2008
0

Re: about big endian and little endian representation

Look at the ByteBuffer class. You can wrap a ByteBuffer around some bytes that you need to decode, then set the byte order on the buffer to either little/big endian (or the machine's native type), then pull out ints etc.

Similarly, to ENCODE a value in little/big endian, allocate a ByteBuffer, set to appropriate endianness, store the value (with putInt() etc), then query the underlying array.

There's some information about ByteBuffer and using them with different byte orders on my web site that might be helpful (and of course take a look at the javadoc).
Reputation Points: 120
Solved Threads: 7
Junior Poster in Training
neilcoffey is offline Offline
53 posts
since Dec 2008
Dec 17th, 2008
0

Re: about big endian and little endian representation

Click to Expand / Collapse  Quote originally posted by AlbertPi ...
This will keep you very busy for a while........... :-)

1. Big endian machine: Stores data big-end first. When looking at multiple bytes, the first byte (lowest address) is the biggest.
Motorola processors are this kind hardware.
Unix
2. Little endian machine: Stores data little-end first. When looking at multiple bytes, the first byte is smallest.
Intel processors are this kind hardware.
Windowsx

Do you need to convert little-E to big-E ?
What is your message is made of text only or number & text ?




Albert
We want to compose message as follow.
for example...

symbol : 5 bytes : alphanumeric
action : 1 byte : alphanumeric
time : 7 bytes : alphanumeric
mc id : 1 bytes : alphanumeric
prize : 10 bytes :numeric

etc.

message can be composed of other fields having data types numeric,alphanumeric,binary integer values etc.
Reputation Points: 9
Solved Threads: 0
Light Poster
srs_grp is offline Offline
34 posts
since Sep 2008
Dec 17th, 2008
0

Re: about big endian and little endian representation

Click to Expand / Collapse  Quote originally posted by neilcoffey ...
Look at the ByteBuffer class. You can wrap a ByteBuffer around some bytes that you need to decode, then set the byte order on the buffer to either little/big endian (or the machine's native type), then pull out ints etc.

Similarly, to ENCODE a value in little/big endian, allocate a ByteBuffer, set to appropriate endianness, store the value (with putInt() etc), then query the underlying array.

There's some information about ByteBuffer and using them with different byte orders on my web site that might be helpful (and of course take a look at the javadoc).


i have tried to import "nio" package in my program but it is giving error as follows:

chk.java:2: package java.nio does not exist
import java.nio.*;
^
1 error


I am using jdk1.4.2 edition?
Is there any solution.
Reputation Points: 9
Solved Threads: 0
Light Poster
srs_grp is offline Offline
34 posts
since Sep 2008
Dec 17th, 2008
0

Re: about big endian and little endian representation

java.io.*
Reputation Points: 9
Solved Threads: 2
Light Poster
AlbertPi is offline Offline
33 posts
since Nov 2008
Dec 17th, 2008
0

Re: about big endian and little endian representation

No, it is java.nio for the ByteBuffer class. And if you're using JDK 1.4, it really should find it! Can't really suggest anything other than make sure your JDK is properly installed and that your IDE is properly set up ti use it.
Reputation Points: 120
Solved Threads: 7
Junior Poster in Training
neilcoffey is offline Offline
53 posts
since Dec 2008
Dec 17th, 2008
-1

Re: about big endian and little endian representation

Do you know what is total bytes of this message ?
Also you can read document about "DataInputStream" from java.io.* of jdk 1.4 or higher version will lead you to understand
what you need to do.

The following sample codes just gives you some ideas.
package com.my.Message;

import java.io.*;


public genMessage {
private ByteArrayOutputStream outputBuffer = null;
private DataOutputStream outputStream = null;
private DataInputStream inputStream = null;

genMessage()
{

outputBuffer = new ByteArrayOutputStream();
outputStream = new DataOutputStream(outputBuffer);
}

public byte readByte(){
try {
return inputStream.readByte();
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
public int readInt(){
try {
return inputStream.readInt();
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
public String readUTF(){
try {
return inputStream.readUTF();
}catch (Exception e) {
System.out.println("Exception: " + e);
}
}
public void writeObj(Object value) {
outputBuffer = new ByteArrayOutputStream();
outputStream = new DataOutputStream(outputBuffer);
try {
if(value instanceof String )
outputStream.writeUTF((String) value);
else if (value instanceof Integer )
outputStream.writeInt(((Integer) value).intValue());
else if ..............

}catch (IOException ie) {
System.out.println("Exception: " + ie);
}
}




Albert
Reputation Points: 9
Solved Threads: 2
Light Poster
AlbertPi is offline Offline
33 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Urgent : Binary Search Tree problem
Next Thread in Java Forum Timeline: Image Path





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC