Origin of Magnetic Fields in White Dwarfs and Neutron Stars