about big endian and little endian representation

Reply

Join Date: Sep 2008
Posts: 34
Reputation: srs_grp is an unknown quantity at this point 
Solved Threads: 0
srs_grp srs_grp is offline Offline
Light Poster

about big endian and little endian representation

 
0
  #1
Dec 16th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 33
Reputation: AlbertPi is an unknown quantity at this point 
Solved Threads: 2
AlbertPi AlbertPi is offline Offline
Light Poster

Re: about big endian and little endian representation

 
0
  #2
Dec 16th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 53
Reputation: neilcoffey will become famous soon enough neilcoffey will become famous soon enough 
Solved Threads: 6
neilcoffey neilcoffey is offline Offline
Junior Poster in Training

Re: about big endian and little endian representation

 
0
  #3
Dec 16th, 2008
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).
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 34
Reputation: srs_grp is an unknown quantity at this point 
Solved Threads: 0
srs_grp srs_grp is offline Offline
Light Poster

Re: about big endian and little endian representation

 
0
  #4
Dec 17th, 2008
Originally Posted by AlbertPi View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 34
Reputation: srs_grp is an unknown quantity at this point 
Solved Threads: 0
srs_grp srs_grp is offline Offline
Light Poster

Re: about big endian and little endian representation

 
0
  #5
Dec 17th, 2008
Originally Posted by neilcoffey View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 33
Reputation: AlbertPi is an unknown quantity at this point 
Solved Threads: 2
AlbertPi AlbertPi is offline Offline
Light Poster

Re: about big endian and little endian representation

 
0
  #6
Dec 17th, 2008
java.io.*
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 53
Reputation: neilcoffey will become famous soon enough neilcoffey will become famous soon enough 
Solved Threads: 6
neilcoffey neilcoffey is offline Offline
Junior Poster in Training

Re: about big endian and little endian representation

 
0
  #7
Dec 17th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 33
Reputation: AlbertPi is an unknown quantity at this point 
Solved Threads: 2
AlbertPi AlbertPi is offline Offline
Light Poster

Re: about big endian and little endian representation

 
-1
  #8
Dec 17th, 2008
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC