Swap even and odd bits of unsigned 8-bit integer
OMDG arrays to manipulate bits
Bit manipulation is the most basic type of operation a computer can do. These days it can mess with 64 bit in one go. JS number (as signed int 32) is limited to 32 (to keep us in our place)
BTW JS has 8, 16, 32bit signed and unsigned arrays.
In JS you can write binary numbers with the 0b prefix. Eg 0b111 is 7
To swap even odd, you shift all bits to the left &lt;&lt; 1 (same as * 2) and mask out &amp; 0b10101010 the odd bits. The for the even you shift all bits to the right &gt;&gt; 1 similar to /2, mask out the even bits &amp; 0b101010101 and add or or the result of the previous shift.
Example show two ways of doing the same thing.


const swapEvenOdd = char =&gt; ((char &lt;&lt; 1) &amp; 0b10101010) | ((char &gt;&gt; 1) &amp; 0b1010101);

const swapEvenOdd2 = char =&gt; ((char * 2) &amp; 170) + ((char / 2) &amp; 85);


console.log(swapEvenOdd(0b01100110).toString(2).padStart(8,"0"))
console.log(swapEvenOdd2(0b01100110).toString(2).padStart(8,"0"))