> For instance, the Sega Genesis encodes 9-bit colors, giving 3-bits per channel.
> The solution to this is that the source bits should repeat to fill in all of the target bits.
000 -> 000 000 00...
010 -> 010 010 01...
011 -> 011 011 01...
111 -> 111 111 11...
This is interesting and efficient approach. Interpolating a 3-bit number (0-7) into a 8-bit one (0-255) can be done by dividing the first one by 7 (to normalize it) and the multiplying it by 255 (to stretch it to the full range). The operation order can be changed to avoid having smaller-than-1 floating numbers in the first step. So, we basically need to multiply each number by 255/7~36.4. 0 -> 0 * 36.4 = 0
1 -> 1 * 36.4 = 36
2 -> 2 * 36.4 = 73
3 -> 3 * 36.4 = 109
...
7 -> 7 * 36.4 = 255
So, these multiplications give exactly the same results as repeating the bits in the byuu's article and bits operations are much cheaper. I have some intuition on how does it work (we're increasing each "part" of the number by the same factor), but not a math explanation.