Page 1 of 1
big-endian and little-endian convertion
Posted: Tue Apr 03, 2012 12:26 am
by hojjatrakhshani
hi guys!
the data that stored in volume boot sector are
little-endian format(such as BIOS Parameter Block).
they must convert to big-endian to use?
if thats right how we can do this convertion?
Re: big-endian and little-endian convertion
Posted: Tue Apr 03, 2012 12:46 am
by AndrewBuckley
what system are you working with? x86 does not need to ever use big endian.
Re: big-endian and little-endian convertion
Posted: Tue Apr 03, 2012 12:53 am
by bluemoon
hojjatrakhshani wrote:the data that stored in volume boot sector are
little-endian format(such as BIOS Parameter Block).
they must convert to big-endian to use?
As above mentioned, what CPU you are using?
hojjatrakhshani wrote:if thats right how we can do this convertion?
If you can't figure it out, you should not touch the boot sector, it's dangerous.
Re: big-endian and little-endian convertion
Posted: Tue Apr 03, 2012 2:01 am
by Yoda
On 486+ CPUs endiannes conversion is performed by BSWAP instruction.
But as Merlin wrote, you don't need to do that on Intel machines since Intel CPUs are little-endian.
Re: big-endian and little-endian convertion
Posted: Tue Apr 03, 2012 2:12 am
by hojjatrakhshani
thanks!
As above mentioned, what CPU you are using?
sorry!i use x86.
for example bytes per sector stored in BPB with this value 00 02
i dont need convert it to 02 00 fo my calculation?
Re: big-endian and little-endian convertion
Posted: Tue Apr 03, 2012 2:55 am
by brain
If you're curious look at the functions ntohs() etc, their internal implementation. these will show you how its done on systems that do need it for if you need it later, e.g. for networking most likely or talking to other systems.
Re: big-endian and little-endian convertion
Posted: Tue Apr 03, 2012 4:31 am
by Solar
Merlin wrote:x86 does not need to ever use big endian.
Ah, you don't want to do TCP/IP?
Re: big-endian and little-endian convertion
Posted: Tue Apr 03, 2012 5:20 am
by bluemoon
The OP say he's working on boot sector
Re: big-endian and little-endian convertion
Posted: Tue Apr 03, 2012 4:24 pm
by Brendan
Hi,
hojjatrakhshani wrote:sorry!i use x86.
for example bytes per sector stored in BPB with this value 00 02
i dont need convert it to 02 00 fo my calculation?
The bytes 0x00, 0x02 would be 0x0200 in little-endian format, which is what an 80x86 CPU expects. Just read them as a 16-bit word (with no byte swapping required).
If it was big endian, then the most significant byte would be first, and it'd be 0x02, 0x00.
Cheers,
Brendan
Re: big-endian and little-endian convertion
Posted: Wed Apr 04, 2012 12:02 am
by AndrewBuckley
Solar wrote:Merlin wrote:x86 does not need to ever use big endian.
Ah, you don't want to do TCP/IP?
I apologise for being presumptuous. I know little of tcp/ip but would be shocked to find any Big Endian components in the Fat filesystem.
Re: big-endian and little-endian convertion
Posted: Wed Apr 04, 2012 1:26 am
by xenos
Well,
if the OP was reading a floppy bootsector on an Atari or some other M68K device, he
would have to convert some data to big-endian - but not on an x86 computer.
Just as an off-topic side note, have you ever wondered where the terms big-endian and little-endian
actually come from?
Re: big-endian and little-endian convertion
Posted: Wed Apr 04, 2012 1:56 am
by AndrewBuckley
I have stumbled upon the explanation before, im agnostic on the subject(like a PPC).