What output representation do you want?
You have
but that is not going to be a single bit except in the special case where Pn == 2^t exactly. Suppose for example that Pn is 3 and t is 1, then B(n,t) would be 3/2^1 which would be 1 1/2 .
Notice too that when defining MSB and LSB you go down to B(n,1) but not to B(n,0) . Thus you are always dividing by at least 2^1 and therefor have no mechanism to get at the bit with the least value (the one that contributes 0 or 2^0 to Pn)
Your notation
does not make any sense to me. Pn = Sum(B(n,t) * 2^t, t=1..8) would make more sense to me.
If my guess is correct about your desired output representation, then my suspicion is that the desired output can be produced in one expression. On the other hand, I suspect that your talk about B(n,t) is an indication of how you are being directed to code this.
Best Answer