#include <stdio.h>
#include <stdint.h>
uint8_t is_circular_match(uint16_t reg, uint16_t target) {
// Your code here
int val=0,i=0;
for(i=15;i>=0;i--){
val = reg>>15&1;
reg = reg<<1;
reg = reg | val<<0;
// print_bin(reg);
// printf("\n");
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;
}
Step 1:- initialize the variables
int val=0,i=0;
Step 2:- iterate the loop up to 16 times
for(i=15;i>=0;i--){
Step 3:- fetching the reg 15 th position bit value and storing in val variable
val = reg>>15&1;
Step 4 :- left shifting reg value each one time till loop condition fails
reg = reg<<1;
Step 5 :- inserting the value at zero position in reg
reg = reg | val<<0;
Step 6:- reg matching with target if matches return 1
if(reg == target){
return 1;
}
}
Step 7:- if reg not matching with target return 0
return 0;
Input
45056 11
Expected Output
1