When Do We Have to Swap Bytes When Changing Computers?

GUIDE: Mathematics of the Discrete Fourier Transform (DFT). When Do We Have to Swap Bytes When Changing Computers?

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.

<< Previous page  TOC  INDEX  Next page >>

When Do We Have to Swap Bytes When Changing Computers?

When moving a soundfile from one computer to another, such as from a “PC” to a “Mac” (Intel processor to Motorola processor), the bytes in each sound sample have to be swapped. This is because Motorola processors are big endian (bytes are numbered from “left to right” in a multi-byte word) while Intel processors are little endian. Any Mac program that supports a soundfile format native to PCs (such as .wav files) will swap the bytes for you. You only have to worry about swapping the bytes yourself when reading raw binary soundfiles from a foreign computer, or when digging the sound samples out an “unsupported” soundfile format yourself.

Since soundfiles typically contain 16 bit samples (not for any good reason, as we now know), there are only two bytes in each audio sample. Let L denote the least-significant byte, and M the most-significant byte. Then a 16-bit word is most naturally written $[M,L] = M\, i.e., the most-significant byte is most naturally written to the left of the least-significant byte, analogous to the way we write binary or decimal integers. This “most natural” ordering is used in big-endian processors:

\

Little-endian machines, on the other hand, store bytes as
\

These orderings are preserved when the sound data are written to a disk file.

Since a byte (eight bits) is the small addressable unit in all modern day processor families, we don’t have to additionally reverse the bitsin each byte. In other words, bits are not given explicit “addresses” in memory. They are extracted by means other than simple addressing (such as masking and shifting operations, table look-up, or by means of specialized processor instructions).

Table 4.7 lists popular present-day processors and their “endianness”:4.10

Table 4.7:Byte ordering in the major computing platforms.
Processor Family Endian
Pentium (Intel) Little
Alpha (DEC/Compaq) Little
680x0 (Motorola) Big
PowerPC (Motorola & IBM) Big
SPARC (Sun) Big
MIPS (SGI) Big

When compiling C or C++ programs under UNIX, there may be a BYTE_ORDER macro in endian.h or bytesex.h. In other cases, there may be a defined macro INTEL, LITTLE_ENDIAN, BIG_ENDIAN, or the like.

<< Previous page  TOC  INDEX  Next page >>

 

© 1998-2017 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy