Qualcomm Interview Question

Identify a 5-bit pattern, given a bit stream, accessible by function uint8_t getBits(), which returns 4 bits at a time.

Interview Answers

Anonymous

Sep 7, 2019

static int flag = 0; int matchPattern (char bitStream[]) //bitstream obtained from the function that returns 4 bits { //extract the first 4 bits of the 5-bit pattern value to be matched in the string Pattern 2 if(flag==1 && bitStream[0]==Pattern[4[) //When the next stream occurs match it with the last bit of the pattern return 1; if(!strcmpi(bitStream,Pattern2)) flag=1; }

1

Anonymous

Jan 16, 2013

#include #include #include using namespace std; int numMatches(vector get_bits, unsigned char pattern){ unsigned char stream = 0x00; int counter = 0; for(int i = 0; i0?1:0); if ((pattern & stream) == pattern){ counter++; } } pattern = pattern >> 3; } return counter; } int main(){ vector get_bits; get_bits.push_back(0x0F); get_bits.push_back(0x0D); get_bits.push_back(0x0F); get_bits.push_back(0x00); unsigned char pattern = 0x1F; cout<