#include <stdio.h>
#include <stdint.h>
uint8_t is_circular_match(uint16_t reg, uint16_t target)
{
int count=1;
while(count<=15) //we need to execute it 15 times. If value is not matched in any of the iteration means there was no target found during shifting operation.
{
count++;
//logic of leftshifting.
uint16_t mask=((reg>>15)&1); //everytime we are fetching bit on LSB and storing in mask.
reg=(reg<<1)|mask; //Implement leftshift by once, we get vacancy on LSB. Now perform XOR with above mask.
if(reg==target)
{
return 1;
}
}
return 0;
}
int main() {
uint16_t reg, target;
scanf("%hu %hu", ®, &target);
printf("%hhu", is_circular_match(reg, target));
return 0;
}
Input
45056 11
Expected Output
1