Qualcomm Interview Question: Identify a 5-bit pattern, giv... | Glassdoor

Interview Question

Software Engineer Interview San Diego, CA

Identify a 5-bit pattern, given a bit stream, accessible by

  function uint8_t getBits(), which returns 4 bits at a time.
Answer

Interview Answer

1 Answer

0

#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<<numMatches(get_bits, pattern);
}

Ambu Sreedharan on Jan 16, 2013

Add Answers or Comments

To comment on this, Sign In or Sign Up.