Website logo
⌘K
😀RetroSix Wiki
💡Learn Electronics
Byte Swapping (BIOS Files)
Digital Logic Levels
Video Standards
đŸ› ī¸Repair & Schematics
Power Supply Details
Amiga (Various)
Amiga 600
Atari 2600
Atari 7800
Atari Jaguar
Atari Lynx
Atari Lynx II
Commodore 16
Commodore 64
Dreamcast
Game & Watch New
Game Boy
Game Boy Pocket
Game Boy Color
Game Boy Advance
Game Boy Advance SP
Game Gear
Mattel Intellivision
Neo Geo AES
Neo Geo CDZ
Panasonic Q
PC Engine
PC Engine Duo
PC Engine Duo-R
PC Engine GT
PlayStation 2
Playstation 5
SNES
Sega Master System
Sega Mega CD
Sega Mega CD 2
Sega Mega Drive
Sega Mega Drive 2
Sega Mega-Tech Arcade
Sega Multi Mega
Sega NAOMI 2
Sega Saturn
Nintendo Switch
Xbox Original
Xbox One S
Xbox One X
Xbox Series S
Xbox Series X
ZX Spectrum 16/48k
ZX Spectrum 128
đŸĻŽInstallation Guides
Game Gear CleanScreen VA4/5
đŸ•šī¸Game Development
đŸ“ĻRetroSix Product Info
International Send-In Repair Service
📐Design Your Own
⚡CleanJuice Air USB-C Install (Game Boy Color)
đŸšĨLED Mods
đŸ› ī¸Send In Repair Service
đŸ’¯Prestige Shells & Consoles
🔋CleanJuice Battery Upgrade
🔊CleanAmp Audio Amplifier
🔍Glass Lenses
đŸŦOrdering & Shipping
Docs powered by Archbee
Learn Electronics

Byte Swapping (BIOS Files)

5min

A common requirement when programming EEPROM BIOS chips is if the console requires the bytes to be swapped.

Let's use a Mega CD as an example.

Here is the Mega CD 1 BIOS in its normal (little-endian) format, usable by emulators.

Mega CD BIOS
Mega CD BIOS
īģŋ

Notice each hexadecimal value (FF for example) represents 256 possible values, so 8 bits also known as 1 byte.

That means each 2 digits in hex is 1 byte.

Big Endian vs Little Endian

The Mega CD reads the BIOS as 16 bit values (so 2 bytes), and the Mega CD reads them in big-endian format. Whereas PC and all emulators are little-endian.

In short, it just refers to the order that bytes are read in.

On PC and most systems, it is little-endian. This means for a 16 bit format (the 2 bytes making up the 16 bits) lets say FD 00, are read by PC in little endian as FD00 (the least significant byte being 00, the Most significant byte being FD).

If we put that FD00 into the Windows Calculator (as Windows is Little-Endian) it will show the value 64,768.

Windows Calculator
Windows Calculator
īģŋ

However, the Mega CD is Big-Endian, so it would ready the first byte FD as the LSB (least significant byte) and 00 as the MSB (most significant byte). This would be the equivalent of 00 FD, which is 253, not 64,768.

Windows Calculator Big Endian
Windows Calculator Big Endian
īģŋ

Byte Swapping

So the goal of the above, is to flip every 2 bytes around before we program the EEPROM, so the little-endian BIOS file becomes big-endian.

If we notice the first row is FF FF FD 00 00 00 04 26 and so on, the groups would be FFFF FD00 0000 0426 and so on.

When we byte-swap, we flip each byte around in each group of two.

So FF and FF are the same, FD 00 however would be swapped, to become 00 FD, and the 04 26 would become 26 04.

In short, take every 2 bytes, and flip them.

Let's group them visually first.

Mega CD BIOS Close Up
Mega CD BIOS Close Up
īģŋ

Now let's flip the bytes around.

This is basically converting little-endian format to big-endian.

Byte Swapped Mega CD BIOS Close Up
Byte Swapped Mega CD BIOS Close Up
īģŋ

Notice the FD00 has become 00FD.

This is more obvious when you look at the embedded text in the file.

Notice how the SEGA text is flipped every byte, so instead of SE it is ES, then instead of GA it is AG.

Document image
īģŋ
Byte Swapped Mega CD BIOS Text
Byte Swapped Mega CD BIOS Text
īģŋ

How To Byte Swap

If you have the BIOS file you want to byte swap, you must first find out what format the system reads the data in (8 bit, 16 bit, 32 bit) and then use a hex editor tool such as HexToolkit to byte swap.

You must select the format size in order to flip the MSB and LSB sections correctly.

For example, 16 bit systems are 2 bytes, so one byte in each two is swapped, also known as Word swapping (as a WORD is 2 bytes long).

Byte swapping (8 bit) is swapping the upper 4 and lower 4 bits of a single byte.

Double Word swapping (32 bit) swaps 2 bytes at a time, so FFAA BBCC becomes BBCC FFAA. If you Word swapped (instead of Double Word swapped) a 32 bit format file, it would incorrectly swap every 2 bytes and become AA FF CC BB.

So you see the importance of understanding not only byte swapping but the end format the file is being read in (what chunks of data at a time, 8/16/32/64 bit).

Updated 07 Aug 2023
Did this page help you?
PREVIOUS
Learn Electronics
NEXT
Digital Logic Levels
Docs powered by Archbee
TABLE OF CONTENTS
Big Endian vs Little Endian
Byte Swapping
How To Byte Swap
Docs powered by Archbee