title: Find longest alternating string of 1's and 0's
body: <p>I am learning bitwise operations in Assembly. In terms of bitwise operations, it is quite forward to find the longest string of 0's or 1's, but how would you find the longest string of alternating 1's and 0's. </p>
  
  <p>I thought it would be something similar to the first two in the sense that you would just need to do a right shift and do the appropriate operation, and then repeat until you had all 0's, but I couldn't figure out the solution. Any ideas on what to do?</p>
  
  <p>Thanks!</p>
  
  <p>EDIT</p>
  
  <p>Some examples:
  101101010001 has a string of 6 alternating 1s and 0s. The number 1010 has a string
  of 4 consecutive 1s and 0s.
  I don't really care for alternating strings of 0's and 1's, so 0101, is only 2 because of the 10 in the middle of it</p>
  
  <p>The architecture I'm using is the ARM A9 processor</p>
  
  <p>Here is what I tried </p>
  
  <pre><code>.text
  .global _start
  _start:
  
  MOV R5, #0//Store final result
  MOV R6, #0
  MOV R2 , #0
  MOV R7, #0
  LDR R3 , =TEST_NUM
  
  ONES: LDR R1, [R3]  //Load the data word into R1 
      MOV R0, #0      // R0 will hold the result
  LOOP: CMP R1, #0     //loop until data contains no more ones
      BEQ NEXT
      LSR R2, R1, #1  //Perform shift, followed by and
      XOR R1, R1, R2
      ADD R0, #1      // count number of iterations
      B LOOP
  NEXT: CMP R5, R0 //
      MOVLE  R5, R0
      B END
  END:   B END
  
  TEST_NUM: .word 0x1fffffff, 0x7fffffff
  .end 
  </code></pre>