To make it easy, the hat-maker imagines your head is perfectly round. He takes the circumference of the circle, and from that finds the diameter. The result is the hat size. Your examples are in inches, but it works in metric too.
So, with a tailor's tape measure, measure the circumference of your head at the widest part, above the ears, and about two fingers width above the eyebrows.
Divide the result by Π (Pi) to get your hat size.