Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Understanding Big Endian and Little Endian Formats for Integers, Exams of Microprocessors

The difference between big endian and little endian formats for representing integers in binary form. It discusses how these formats are used in various computer systems and file formats, and provides an example of how to determine the endian format of a file using the unix od command. It also includes a code snippet for converting the endian format of an integer.

Typology: Exams

2021/2022

Uploaded on 09/12/2022

ahalya
ahalya 🇺🇸

4.9

(16)

257 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
“Big Endian” and “Little Endian” Formats for Integers
In base 10, integers are represented with the most significant digit first;
e.g., 9,263. A 16-bit (2’s complement) representation of this number in
base 2 or base 16 (hexadecimal, or hex) is given by
926310 = 0010 0100 0010 11112 = 24 2F16
and its inverse by
-926310 = 1101 1011 1101 00012 = DB D116.
If the representation is extended to 32-bit 2’s complement (represented
in hex) the numbers become
926310 = 00 00 24 2F16
and -926310 = FF FF DB D116.
This representation has the advantage of lining up the bytes in the way
people are used to writing numbers, which is not necessarily the best
way at the level of hardware.
A commonly used practice (e.g., Intel microprocessors employ this) is to
change the byte order of the number to have the lowest byte first (the
bits within each byte still have highest order bit first); e.g.,
926310 is stored in the order 2F 24 00 00
and -926310 is stored in the order D1 DB FF FF.
This has been dubbed the “little endian” format. The advantage is that
the number starts at the same address in memory, regardless of the
precision (16-bit, 32-bit, 64-bit, etc), facilitating construction of
extended precision routines for arithmetic regardless of data path width.
A byte order that conforms to the “natural” order has been dubbed “big
endian”, since the most significant byte comes first. It is not without
advantages. The sign of the number is on the first byte. For little
endian, you have to know how long the representation is and index to
the last byte to find the sign. Also since the order conforms to print
pf3

Partial preview of the text

Download Understanding Big Endian and Little Endian Formats for Integers and more Exams Microprocessors in PDF only on Docsity!

“Big Endian” and “Little Endian” Formats for Integers

In base 10, integers are represented with the most significant digit first; e.g., 9,263. A 16-bit (2’s complement) representation of this number in base 2 or base 16 (hexadecimal, or hex) is given by 9263 10 = 0010 0100 0010 1111 2 = 24 2F 16 and its inverse by -9263 10 = 1101 1011 1101 0001 2 = DB D1 16.

If the representation is extended to 32-bit 2’s complement (represented in hex) the numbers become 9263 10 = 00 00 24 2F (^16) and -9263 10 = FF FF DB D1 16.

This representation has the advantage of lining up the bytes in the way people are used to writing numbers, which is not necessarily the best way at the level of hardware.

A commonly used practice (e.g., Intel microprocessors employ this) is to change the byte order of the number to have the lowest byte first (the bits within each byte still have highest order bit first); e.g., 9263 10 is stored in the order 2F 24 00 00 and -9263 10 is stored in the order D1 DB FF FF. This has been dubbed the “little endian” format. The advantage is that the number starts at the same address in memory, regardless of the precision (16-bit, 32-bit, 64-bit, etc), facilitating construction of extended precision routines for arithmetic regardless of data path width.

A byte order that conforms to the “natural” order has been dubbed “big endian”, since the most significant byte comes first. It is not without advantages. The sign of the number is on the first byte. For little endian, you have to know how long the representation is and index to the last byte to find the sign. Also since the order conforms to print

order, converting to print form is simplified. Motorola processors employ a big endian format.

This distinction spills over to non-ASCII file formats, where numeric data is represented in binary form, so you have to know whether to store numbers in big endian or little endian for “standard” programs to process your file. For example, the Windows graphics “.bmp” format is strictly little endian. If a little endian machine is being used, this poses no problem, but if the machine is big endian, the byte order of numbers has to be changed when they are written to file.

Adobe Photoshop uses big endian, “gif” files are little endian, “jpg” files are big endian, and “tiff” files handle either (as data is written, an identifier to tell which endian format is being used has to be included with it).

Unix od command

One way to determine the endian format being used is to employ the Unix od command:

od displays the contents of the file byte by byte (octal dump) usage: "od –xc < filename >" (exhibits the file byte by byte in both hex and ASCII)

The c option directs od to exhibit the byte order of the file as ASCII

characters. The x option directs od to exhibit the file in 16 bit (2 byte)

chunks. On Osprey, integers are in little endian (with long 64 bits and int 32 bits). If the integer X’43444546’ (chosen because it also can be

interpreted as characters) is written to file exod, then od –xc exod

returns 0000000 4546 4344 F E D C 0000010