Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

need a concept  RSS feed

 
alfred jones
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, i dont understand big endian and little endian concept. its quiet complex to me.

suppose i want to convert 280 into byte array .

so that means this value will be stored into 2 bytes. because first byte will
contain 256 and second byte will contain contain 24 (as 256+24=280).

so what those big endian and little endian are meant for ? what role they could have in this context ? do they have any role ?
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First things first, the high-order byte of the number is going to be 1 -- not 256. It will become 256 in the resulting number because you are shifting it 8 bits (multiplying by 256). The bytes will be 1 and 24.

They determine the order those bytes appear in the array. According to Wikipedia, big endian puts the most significant byte into the first byte (lowest memory address) of the array. Little endian puts the least significant byte first.Because the hardware specifies which to use normally, and programs on different hardware have to communicate, "network order" was created, and it follows big endian. I believe Java uses this by default in the JVM for simplicity.

[ Added: ]

Also, since you're starting to deal with bytes and composition of larger numbers, I recommend learning hexadecimal notation if you haven't already.

The number 280 converted to hexadecimal is 0x118. The handy thing with hexadecimal is that each two digits form a byte, so it's clear that 280 is broken up into two bytes: 0x01 and 0x18.
[ April 28, 2005: Message edited by: David Harkness ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"alfred"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!