Charcoal, 4242 41 bytes
≔E⮌↨N²…1ιθF24HBSI≔E⪪θ²⪫⮌EΦκ∨μ¬ν⎇∧ν⁼μ1ωμιθθ≔⁻I⮌↨N²0θF24HBSI≔E⪪θ²⪫⮌EΦκ∨μ¬ν⎇∧ν⁼μ1ωμιθθ
Try it online!Try it online! Link is to verbose version of code. Supports numbers from 1
to 18446744073709551615
. Explanation:
≔E⮌↨N²…1ιθ≔⁻I⮌↨N²0θ
Convert the input to a list of 1
s and empty strings according to the reverse of its binary representation.
F24HBSI
Loop over the additional possible "digits".
≔E⪪θ²⪫⮌EΦκ∨μ¬ν⎇∧ν⁼μ1ωμιθ
Group the existing digit blocks into pairs, then for each pair, create a new digit block by removing any second part if it is zero, or making it the empty string if it is one, switching the parts, and joining on the next digit.
θ
Output the final result.