  The hull of a linear code $C$ is the intersection of $C$ with its dual. To
the best of our knowledge, there are very few constructions of binary linear
codes with the hull dimension $\ge 2$ except for self-orthogonal codes. We
propose a building-up construction to obtain a plenty of binary $[n+2, k+1]$
codes with hull dimension $\ell, \ell +1$, or $\ell +2$ from a given binary
$[n,k]$ code with hull dimension $\ell$. In particular, with respect to hull
dimensions 1 and 2, we construct all binary optimal $[n, k]$ codes of lengths
up to 13. With respect to hull dimensions 3, 4, and 5, we construct all binary
optimal $[n,k]$ codes of lengths up to 12 and the best possible minimum
distances of $[13,k]$ codes for $3 \le k \le 10$. As an application, we apply
our binary optimal codes with a given hull dimension to construct several
entanglement-assisted quantum error-correcting codes(EAQECC) with the best
known parameters.
