big-endian and little-endian convertion

Programming, for all ages and all languages.
Post Reply
hojjatrakhshani
Posts: 21
Joined: Sun Feb 19, 2012 7:25 am

big-endian and little-endian convertion

Post 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?
AndrewBuckley
Member
Member
Posts: 95
Joined: Thu Jan 29, 2009 9:13 am

Re: big-endian and little-endian convertion

Post by AndrewBuckley »

what system are you working with? x86 does not need to ever use big endian.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: big-endian and little-endian convertion

Post 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.
User avatar
Yoda
Member
Member
Posts: 255
Joined: Tue Mar 09, 2010 8:57 am
Location: Moscow, Russia

Re: big-endian and little-endian convertion

Post 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.
Yet Other Developer of Architecture.
OS Boot Tools.
Russian national OSDev forum.
hojjatrakhshani
Posts: 21
Joined: Sun Feb 19, 2012 7:25 am

Re: big-endian and little-endian convertion

Post 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?
Last edited by hojjatrakhshani on Tue Apr 03, 2012 2:58 am, edited 1 time in total.
User avatar
brain
Member
Member
Posts: 234
Joined: Thu Nov 05, 2009 5:04 pm
Location: UK
Contact:

Re: big-endian and little-endian convertion

Post 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.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: big-endian and little-endian convertion

Post by Solar »

Merlin wrote:x86 does not need to ever use big endian.
Ah, you don't want to do TCP/IP? :twisted:
Every good solution is obvious once you've found it.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: big-endian and little-endian convertion

Post by bluemoon »

The OP say he's working on boot sector
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: big-endian and little-endian convertion

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
AndrewBuckley
Member
Member
Posts: 95
Joined: Thu Jan 29, 2009 9:13 am

Re: big-endian and little-endian convertion

Post by AndrewBuckley »

Solar wrote:
Merlin wrote:x86 does not need to ever use big endian.
Ah, you don't want to do TCP/IP? :twisted:
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.
User avatar
xenos
Member
Member
Posts: 1118
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: big-endian and little-endian convertion

Post 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?
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
AndrewBuckley
Member
Member
Posts: 95
Joined: Thu Jan 29, 2009 9:13 am

Re: big-endian and little-endian convertion

Post by AndrewBuckley »

I have stumbled upon the explanation before, im agnostic on the subject(like a PPC).
Post Reply