Solution to binary exercise