If you interpret the bit mask as encoding a finite set $S = \{2^{b_i}\}$ of powers of $2$, you are precisely asking whether there exists a subset of $S$ which sums to $A$ modulo $p$. This is known as the modular subset-sum problem, and apparently there are efficient algorithms for it, for example [https://arxiv.org/pdf/2008.10577.pdf][1] [1]: https://arxiv.org/pdf/2008.10577.pdf