The recent thread(http://www.plctalk.net/qanda/showthread.php?t=43018) about finding adjacent ones piqued my interest. Is there an easier, faster way to do this than sequentially searching through every bit pair of interest?
After some experimentation I found something I think works fairly well. For test purposes I used three sixteen-bit words. The processor is a PLC-5
1. AND the two LSBs of the least significant word. Obviously, if both of these are ON the condition is met
2a. Make a copy of the argument(s)
2b. Right-shift the copy by one bit. This is easily done on A-B processors with the BSR instruction. In fact, if the words are contiguous, only one instruction is needed to shift dozens or hundreds of bits.
2c. AND the copy with the original argument into RESULT
2d. Test RESULT for a non-zero condition. This test can be done on individual words or a whole file. Any non-zero result word indicates that two adjacent bits are set.
If you're looking for zeroes you could NOT the argument before processing starts.
A caveat, make sure the bit shifted in to the BSR is always zero or you may get an erroneous hit.
Comments?
After some experimentation I found something I think works fairly well. For test purposes I used three sixteen-bit words. The processor is a PLC-5
1. AND the two LSBs of the least significant word. Obviously, if both of these are ON the condition is met
2a. Make a copy of the argument(s)
2b. Right-shift the copy by one bit. This is easily done on A-B processors with the BSR instruction. In fact, if the words are contiguous, only one instruction is needed to shift dozens or hundreds of bits.
2c. AND the copy with the original argument into RESULT
2d. Test RESULT for a non-zero condition. This test can be done on individual words or a whole file. Any non-zero result word indicates that two adjacent bits are set.
If you're looking for zeroes you could NOT the argument before processing starts.
A caveat, make sure the bit shifted in to the BSR is always zero or you may get an erroneous hit.
Comments?