문제

I want to use 2bits to switch on and off parts of a mathematical statement in a loop. Kinda like:

Result[i] = someMath*bits[0] + someMath*bits[1]

(bits[n] refers to index n, not a value of n)

Using them as flags but then in each loop I then want to increment them more as a binary encoded value:

bits++

So with each iteration the 2bits will cycle through 00,01,10,11,00,01 ...

Searching I found bitfields but I don't see an increment or array like way to access the elements.

Any ideas appreciated.

If it has to be 8bits, that's fine, the lowest two bits will still follow the pattern I'm after ;)

도움이 되었습니까?

해결책

Result[i] = someMath*(bits&1) + someMath*((bits&2)>>1)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top