• Post Reply Bookmark Topic Watch Topic
  • New Topic

Byte order conversion question  RSS feed

 
Mike Bates
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to understand what is going on in the for loop below and how
to get the byte array in the correct order.

I am not concerned that I am putting a long into 4 bytes because the number will not
get larger then 0x00FFFFFF.

So, how do I get the bytes in the correct order and why do they not go back in the
correct order?

Thanks
Mike



Output:

 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems that arr2long uses Big Endian to convert; otherwise the result would have been 4294967040. Your conversion back uses Little Endian though. See http://en.wikipedia.org/wiki/Endianness. Try using b[i] instead.
 
Mike Bates
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob,

Thanks for the response. This solved my issue.

Regards,
Mike
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!