• Post Reply Bookmark Topic Watch Topic
  • New Topic

Endianness  RSS feed

 
Akil Kumar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to send a packet to the server which accepts data in little endian. I am sending the packet from Java client which is big endian. I have this method to convert big endian to little endian but it does not seem to be working at the server side. I mean the correct data is not being sent to the server. Can anyone please check and give some suggestions?

public static byte[] convertBigEndianToLittleEndianByteArray(int i)
{
ByteBuffer buffer = ByteBuffer.allocate(4);
buffer.order(ByteOrder.LITTLE_ENDIAN).putInt(i);
byte [] b = buffer.array();
System.out.print("Little endian buffer of " + i + " = ");
for(int x=0; x<b.length; x++) System.out.print(b[x] + " ");
System.out.println();
return b;
}

Thanks,
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran your code and it looks like the byte order gets switched when changing from big endian to little endian. Please share your client and server code. It would be a great help if you UseCodeTags. Here's the code I tested:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!