hello I am working on a simple combinatorics part, and found that I need to recover position of two bits given position of other two bits in 4-bits srring.
for example, (0,1) maps to (2,3), (0,2) to (1,3), etc. for a total of six combinations.
My solution is to test bits using four nested ternary operators:
ab is a four bit string, with two bits set.
c = ((((ab & 1) ? (((ab & 2) ? ... ))) : 0)
abc = ab | c
recover the last bit in the same fashion from abc.
I have to clarify, without using for loops, my target language is C++ meta-programming templates. I know I specified language explicitly, but it's still agnostic in my opinion
can you think of a better way/more clever way? thanks