Finite and infinite hypercubes as direct products