views:

188

answers:

1

How could I convert binary to decimal in ocaml in the following, If I am representing binary numbers like the following 01 is [False; True] which equals 2? I want to write a method to return the double of the number in decimal form. For example in this case the method will take in [False; True] and return [False; False, True] which is 4.

+2  A: 

To double a number, add a Zero in front of its binary representation.

let double n = False :: n ;;

Pascal Cuoq
How could I return the integer representation of the list??
Polly Hollanger
@Polly You can do it either with a recursive function you write yourself, or with `List.fold_left`.
Michael E