language agnostic - Find a pattern of binary numbers using shift-right and bitwise-AND? -
I am trying to write a function in the assembly that will find out that now there is a small binary pattern in a binary number.
Example:
Does 100111 contain 1001 ?
When I read this problem, I felt that when I changed the linear (logical) in a loop with a bitwar- and large number and its small pattern,
So, in my head I thought it would be:
100111 and 1001 = 0 Shift-right 1 010011 and 1001 = 0 Shift-right 1 001001 and 1001 = 1 // found pattern! And repeat it until it becomes zero or else returns 1.
However, I think I should be confused because it is returning 1 for most things I keep on the first part of the loop. Am I confused on my use?
The problem is that "partial matches" also returns a non-zero value for your end check It is:
100111 and 001001 = 000001 then this test matches any bits, but you are sure All bits are the same and should be equivalent to the pattern you are looking for:
x = 100111 if found (printed by X and 1001 == 1001) "
Comments
Post a Comment