| | |
about big endian and little endian representation
![]() |
•
•
Join Date: Sep 2008
Posts: 34
Reputation:
Solved Threads: 0
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?
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?
•
•
Join Date: Nov 2008
Posts: 33
Reputation:
Solved Threads: 2
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
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
•
•
Join Date: Dec 2008
Posts: 53
Reputation:
Solved Threads: 6
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).
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).
•
•
Join Date: Sep 2008
Posts: 34
Reputation:
Solved Threads: 0
•
•
•
•
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
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.
•
•
Join Date: Sep 2008
Posts: 34
Reputation:
Solved Threads: 0
•
•
•
•
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.
•
•
Join Date: Nov 2008
Posts: 33
Reputation:
Solved Threads: 2
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
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
![]() |
Similar Threads
- Simple Data Type (C++)
- trying to use substr to extract data from a string of bytes, help would be great (C++)
- Typecasting on littleendian and bigendian (C++)
- converting numbers (C++)
- How to transport a file with QTcpSock in LAN? (C++)
- Array limit (C)
Other Threads in the Java Forum
- Previous Thread: Urgent : Binary Search Tree problem
- Next Thread: Image Path
| Thread Tools | Search this Thread |
actuate add android api applet application applications array arrays automation balls bank binary bluetooth business chat class clear client code codesnippet collections component database defaultmethod development dice digit dragging ebook eclipse equation error event formatingtextintooltipjava fractal functiontesting game givemetehcodez graphics gui health hql html hyper ide idea image infinite int integer invokingapacheantprogrammatically j2me java javame javaprojects jni jpanel julia linux list main map method methods mobile myregfun mysql netbeans nonstatic openjavafx parameter pearl php problem program project recursion repositories scanner scrollbar server set sms sort sorting spamblocker sql sqlserver state storm string sun superclass swing swt thread threads tree windows





