sarahclark Posted May 24, 2016 Report Posted May 24, 2016 I have to check 1024 (sequential) bits for change of state in any of the bits and record which bit changed. I was going to do something like this: A = ARRAY[0..63] OF INT (gives me 1024 bits to check) B = ARRAY[0..63] OF INT (reference array to compare against) WordIndex = INT BitIndex = INT Res = INT (record bit location) FOR (WordIndex :=0 TO 63) DO FOR (BitIndex :=0 TO 15) DO IF A[WordIndex].[BitIndex] NE B[WordIndex].[BitIndex] THEN B[WordIndex].[BitIndex] := A[WordIndex].[BitIndex]; Res := (WordIndex*16) + BitIndex; (other stuff) ; END_IF; END_FOR; END_FOR; Only problem is that Unity won't let me reference the bits in the word like this. A[WordIndex].0 is fine, A[WordIndex].[BitIndex] is not. Is my syntax wrong or is this not possible? Quote
leon78 Posted May 24, 2016 Report Posted May 24, 2016 This is not possible. You must use mask for your case: FOR (WordIndex :=0 TO 63) DO FOR (BitIndex :=0 TO 15) DO wMask := SHL(16#0001, BitIndex ); IF A[WordIndex] AND wMask NE B[WordIndex] AND wMask THEN B[WordIndex] :=(B[WordIndex] AND NOT wMask) OR (A[WordIndex] AND wMask) ; Res := (WordIndex*16) + BitIndex; (other stuff) ; END_IF; END_FOR;END_FOR; 1 Quote
sarahclark Posted May 25, 2016 Author Report Posted May 25, 2016 leon78, that's exactly what I was after. Thank you very much :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.