As is well known, any real in [0,1] can be written as a binary expansion in base 1/2:
x = b1 * 1/2^1 + b2 * 1/2^2 + ...
I would like an efficient way to get bi for a given x and index i, and I don’t think there’s any built-in way to do that in Mathematica. IntegerDigits and RealDigits don’t seem to be able to help, and none of the related functions are pertinent.
The obvious solution is to do the manual conversion, but I was hoping to avoid that. Am I missing something?
EDIT: for future reference, what I was looking for can be done this way,
BinaryExpansionBit[p, j] := RealDigits[p, 2, 1, -j][[1]][[1]]
where
BinaryExpansionBit[x, i]
gives the bi I was talking about.
It depends on what you mean by “efficient”. Mathematica can easily convert to binary, as this Wolfram Alpha example shows.
Otherwise what you are looking for is the parity of the integer part of
x * 2^i.