// file: toBinaryLSBF.rex // author: Robert Keller // purpose: to convert a number to a list of its binary bits, // least-significant bit first toBinaryLSBF(0) => [0]; toBinaryLSBF(N) => toBinaryLSBFaux(N); toBinaryLSBFaux(0) => []; toBinaryLSBFaux(N) => [N%2 | toBinaryLSBFaux(N/2)]; // Rationale: The number 0 is handled specially, since we don't want // 0 to be converted to [] (no bits). // N%2 gives the least-significant bit of N; // N/2 is truncating integer arithmetic, which effectively shifts the binary // representation one place to the right, losing the LSB. // Calling toBinaryLSBFaux recursively does the rest. test() = map(toBinaryLSBF, range(0, 16));