9 lines
246 B
Text
9 lines
246 B
Text
/* convert a list of digits in base `base' to a decimal integer */
|
|
digits2dec(l, base):= block([s: 0, po: 1],
|
|
for di in reverse(l) do (s: di*po + s, po: po*base),
|
|
s)$
|
|
|
|
digits2dec([1, 2, 3], 10);
|
|
/* 123 */
|
|
digits2dec([1, 0, 0, 0], 2);
|
|
/* 8 */
|