I was reading bit twiddling hacks for computing parity from this link: Bit Twiddling Hacks
For computing parity, there is a lookup method, which generates parity table for integers from 0 to 255 with 5 codes of line.
#define P2(n) n, n ^ 1, n ^ 1, n
#define P4(n) P2(n), P2(n ^ 1), P2(n ^ 1), P2(n)
#define P6(n) P4(n), P4(n ^ 1), P4(n ^ 1), P4(n)
#define LOOK_UP P6(0), P6(1), P6(1), P6(0)
unsigned int table[256] = { LOOK_UP };
I checked the values P2(n) and P4(n) which calculates the parity for [0..15]. But I didn't understand the intuition behind these lines of code. How do these lines calculate the parity of [0..255]? I want to know the intuition and theory behind this recursive approach. Thanks in advance.