every Nth bit of on first number(expressed binary) forms the other number

326 Views Asked by At

I want to simplify a condition that checks if every Nth bit of on first number(expressed binary) forms the other number (expressed binary). One way to express it is condition expression. Another way is arithmetic expression.

Is there any way to simplify this condition so that it would not involve sum(Σ) or quantifier? It would be easy if there were some elementary function that adds(or removes) N bits after each bit. I don't need program in any programing language, that does it, but a function in common mathematical symbols. It would also be good answer if someone explained why it is impossible.

for example condition is satisfied if n1=4196 n2=23 N=3, because:

4196=11001011011012 and 23=101112

1

There are 1 best solutions below

0
On

I don't think you can do this with a formula. You will need a loop of some kind since you have to compare the binary expansions.

One possible algorithm: insert $0$ bits between the bits of $n_2$, mask the corresponding bits of $n_1$, then check for equality.

It's the insertion that requires a loop. You're essentially using the base $2$ digits to find the corresponding number if you think of them as base $2^N$ digits.

Note: I think this is cleaner if you count digits starting from the right rather than the left.