![]() |
| ||
| about big endian and little endian representation 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? |
| ||
| 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 |
| ||
| 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). |
| ||
| Re: about big endian and little endian representation Quote:
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. |
| ||
| Re: about big endian and little endian representation Quote:
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. |
| ||
| Re: about big endian and little endian representation java.io.* |
| ||
| 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. |
| ||
| 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 |
| All times are GMT -4. The time now is 10:02 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC