# [Unix TMG], 49 bytes This translation-oriented language from 1972 makes this task trivial: p:parse(b); b:<->b b={2 1<->}|<0>={<0>}|<1>={<1>}; I believe, this is the first solution in this language on this website. So, even though it's relatively readable, I will explain just a bit: p: parse(b); # parse() builtin: execute parsing rule `b` and output its translation b: <-> b b = { 2 1 <-> } # encountering "-" do recursion; translation rule is in braces | <0> = { <0> } # otherwise: encountering "0" - translate as "0" | <1> = { <1> }; # otherwise: encountering "1" - translate as "1" [Unix TMG]: https://github.com/amakukha/tmg