faster extend 8-bit mask to 16-bit for MCU
I believe what you are looking for are Morton numbers of x with x.

Various ways for computing Morton numbers: Bit Twiddling hacks

Specializing the binary magic numbers method for 8-bit input and 16 bit output (C-style code):

uint16_t x; // set lower 8 bits of x for input

x = (x | (x &lt;&lt; 4)) &amp; 0x0f0f;
x = (x | (x &lt;&lt; 2)) &amp; 0x3333;
x = (x | (x &lt;&lt; 1)) &amp; 0x5555;

uint16_t res = x | (x &lt;&lt; 1); // could also store result in place


This handles any combination of input bits. Ex.: if x = 0x5 (0b101), then res = 0x33 (0b110011)