How to do matrix conversions by row and columns toggles?

后端 未结 8 1941
半阙折子戏
半阙折子戏 2021-01-13 12:01

I have got a square matrix consisting of elements either 1 or 0. An ith row toggle toggles all the ith row elements (1 becomes 0 and vice versa) and jth column toggle toggle

8条回答
  •  一向
    一向 (楼主)
    2021-01-13 12:29

    Rather than look at this as a matrix problem, take the 9 bits from each array, load each of them into 2-byte size types (16 bits, which is probably the source of the arrays in the first place), then do a single XOR between the two.

    (the bit order would be different depending on your type of CPU)

    The first array would become: 0000000001111101 The second array would become: 0000000111110101

    A single XOR would produce the output. No loops required. All you'd have to do is 'unpack' the result back into an array, if you still wanted to. You can read the bits without resorting to that, though.i

提交回复
热议问题