1. Didn't you hear the alarm?
2. Did you not hear the alarm?
Let's imagine that there is a fire alarm at your school and you did not leave the building and the school manager is angry. He might say "Didn't you hear the alarm?" meaning he thinks you did but ignored it.
Now, let's imagine you want to check the effectiveness of the alarm so you send a student to the furthest point in the building and ask "Did you hear the alarm?" That is a genuine question because you need the information.
This is the most common difference between the two forms.
Both sentences are asking the same question and they both mean the same thing.
1. Didn't you hear the alarm? This is how we speak and it is informal.
2. Did you not hear the alarm? This is more advanced and more formal.
Both sentences are asking if the person heard the alarm.
We could also ask the question this way:
Did you hear the alarm?
Sentences that ask a question and use a negative word like "not" are called "negative interrogative sentences".
Here is a link to an explanation:
"Did you not" is much more formal. One may say to an errant child, or a barrister may ask someone on the wittness stand "did you not...?" Or could say "You did it, did you not?"
Do you notice how much more forceful it sounds?
The contraction "didn't" is softer and also would be classified as informal.