0

Find_sequence (unsigned int num, unsigned int pattern) returns the index of the first occurence the bit ‘pattern’ is found in num. e.g. the bits in num = 10010 and pattern = 1001 should return 1 because the pattern was found at index 1 in num.

Well I dont know how to implement it though. I tried different ways but it does not work....Any help will appreciated. Sorry if this question is simple. I just started learning bits thing.

max
  • 167
  • 2
  • 9
  • 5
    Stack Overflow is not a code writing service. – user703016 Nov 04 '15 at 01:04
  • I know it's not a code writing service. I just started using Stackoverflow and have no idea about it. We just covered bits today in class and our professor directly gave us this question. We just covered the basics. I already spent 2 hours before asking here – max Nov 04 '15 at 01:12
  • 2
    In that case please post what you've tried. We can't help if you don't show us what you've attempted. – user703016 Nov 04 '15 at 01:13
  • You need to help us by at least explaining what you have tried, or thought about and what specifically you don't understand. For example, have you covered C bitwise operators? If not, then go learn that. If already covered then explain what specific difficulty you have in applying that to your problem - by showing the code you have tried. You'll usually get more help on SO if you have demonstrated your efforts and have a specific question. – kaylum Nov 04 '15 at 01:16
  • What will be helpful is a loop that employs a right shift `>` and a bitwise `&` with the pattern to determine if there is a match. If there is a match, the index will be the loop count at the time it tests true. – David C. Rankin Nov 04 '15 at 02:14

0 Answers0