A Pokemon can have 3 abilities (ability 0, ability 1, and ability 2). The game stores the ability number separate from the actual ability value so that when it evolves, it can grab the correct ability if it is supposed to change.
For example, Feebas->Milotic
0: Swift Swim -> Marvel Scale
1: Oblivious -> Competitive
2: Adaptability -> Cute Charm
The game stores the ability number as a bitflag; 1<<x, where x is the ability bit (0/1/2). Calculating these values,
1<<0 = 1
1<<1 = 2
1<<2 = 4
Hence why for hidden abilities, you'd use 4 for the AbilityNumber.