given two bits in a set of four, fine position of two other bits
- by aaa
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.
can you think of a better way/more clever way?
thanks