// file: fromBinaryMSBF.rex // author: Robert Keller // purpose: to create a number from a list of bits, most-significant bit first fromBinaryMSBF(L) = fromBinaryMSBFaux(L, 0); fromBinaryMSBFaux([], Acc) => Acc; fromBinaryMSBFaux([A | L], Acc) => fromBinaryMSBFaux(L, 2*Acc + A); // The accumulator Acc holds the result of the more significant bits already // converted. As each new bit is encountered, Acc is doubled, which // effectively shifts the bits of the result to the left. The current // digit A is added in. This process repeats until all bits are taken // into account. The most-significant bit will have been multiplied by 2 // a number of times one less than the length of the list. The least // significant bit will be the last to be added. When the list is decimated, // the accumulated value is returned. sys(in, "toBinaryMSBF.rex"); // for test purposes test() = map(fromBinaryMSBF, map(toBinaryMSBF, range(0, 16)));