Finding the degrees between two headings

Hi,

I have what I'm sure is a relatively simple problem, but the answer eludes me. (Headbang)

What is the equation to determine the number of degrees between two compass headings? For example:

If Heading 1 is 350 degrees & Heading 2 is 10 degrees then the delta is 20 degrees

or

If Heading 1 is 350 degrees & Heading 2 is 317 degrees then the delta is 33 degrees.

One other thing; the delta can obviously never be greater than 180 degrees.

All help appreciated.

Nomad.