Guide API
Skip to main content

bios_to_xterm16

Function bios_to_xterm16 

Source
pub const fn bios_to_xterm16(bios: u8) -> u8
Expand description

Swap the red and blue bits of a 4-bit BIOS colour index.

BIOS bit layout: bit0=blue, bit1=green, bit2=red, bit3=bright. xterm-16 layout: bit0=red, bit1=green, bit2=blue, bit3=bright.

The swap is (x & 0b1010) | ((x & 1) << 2) | ((x >> 2) & 1). It is its own inverse, so the same operation converts in both directions.