Binary to decimal - prolog
问题 I found this on stack: reversible "binary to number" predicate But I don't understand :- use_module(library(clpfd)). binary_number(Bs0, N) :- reverse(Bs0, Bs), binary_number(Bs, 0, 0, N). binary_number([], _, N, N). binary_number([B|Bs], I0, N0, N) :- B in 0..1, N1 #= N0 + (2^I0)*B, I1 #= I0 + 1, binary_number(Bs, I1, N1, N). Example queries: ?- binary_number([1,0,1], N). N = 5. ?- binary_number(Bs, 5). Bs = [1, 0, 1] . Could somebody explain me the code Especialy this : binary_number([], _,