Jump to content

Recommended Posts

Posted
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?
Posted

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;

  • Like 1

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...