NOTES ===== Original expression from http://www.thedailywtf.com/forums/51291/ShowPost.aspx Each line is a simlification of the previous one. Explanation ofeach simlification is given in square brackets [] Enjoy! (x&(x|~x)&~x)?x&(x^~x):((((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [x|~x has all bits set] (x&(all bits 1)&~x)?x&(x^~x):((((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [x&(all bits 1) = x] (x&~x)?x&(x^~x):((((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [x&~x = 0] (0)?x&(x^~x):((((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [0?a:b = b] ((((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [1<<4 = 0x10 = 16] ((((((x&(~((1<<(0x10))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [1<<0x10 = 0x10000] ((((((x&(~((0x10000)-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [0x10000-1 = 0xffff] ((((((x&(~(0xffff)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [~0xffff = 0xffff0000 (32-bit ints)] ((((((x&(0xffff0000))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [x&(0xffff0000) = x with bottom 16 bits zeroed] ((((((x with bottom 16 bits zeroed)>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [1<<4 = 0x10] ((((((x with bottom 16 bits zeroed)>>(0x10))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [(x with bottom 16 bits zeroed) right-shifted by 16 bits is the top 16 bits of x right-shifted 16 bits.] (((((top 16 bits of x right-shifted 16 bits)|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [(1<<(1<<4))-1 = 0xffff] (((((top 16 bits of x right-shifted 16 bits)|((x&(0xffff))<<((1<<5)-(1<<4))))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [x&(0xffff) = x with top 16 bits zeroed] (((((top 16 bits of x right-shifted 16 bits)|((x with top 16 bits zeroed)<<((1<<5)-(1<<4))))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [1<<5 = 0x20, 1<<4 = 0x10] (((((top 16 bits of x right-shifted 16 bits)|((x with top 16 bits zeroed)<<((0x20)-(0x10))))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [0x20 - 0x10 = 0x10 (decimal: 32 - 16 = 16)] (((((top 16 bits of x right-shifted 16 bits)|((x with top 16 bits zeroed)<<(0x10)))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [(x with top 16 bits zeroed)<<(0x10) is the bottom 16 bits of x left shifted 16 bits] (((((top 16 bits of x right-shifted 16 bits)|(bottom 16 bits of x left shifted 16 bits))&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [(top 16 bits of x right-shifted 16 bits)|(bottom 16 bits of x left shifted 16 bits) is the two 16 (double-byte) halves of x swapped) ((((dbytes of x swapped)&(~((1<<(1<<4))-1)))>>(1<<4))|(((((x&(~((1<<(1<<4))-1)))>>(1<<4))|((x&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))&((1<<(1<<4))-1))<<((1<<5)-(1<<4))))?x|~x:x&~x [substitute 0x10 for 1<<4 and 0x20 for 1<<5 throughout (could have done this earlier.)] ((((dbytes of x swapped)&(~((1<<(0x10))-1)))>>(0x10))|(((((x&(~((1<<(0x10))-1)))>>(0x10))|((x&((1<<(0x10))-1))<<((0x20)-(0x10))))&((1<<(0x10))-1))<<((0x20)-(0x10))))?x|~x:x&~x [substitute 0x10000 for 1<<0x10 and ox10 for (ox20 - 0x10) throughout.] ((((dbytes of x swapped)&(~((0x10000)-1)))>>(0x10))|(((((x&(~((0x1000)-1)))>>(0x10))|((x&((0x10000)-1))<<(0x10)))&((0x10000)-1))<<(0x10)))?x|~x:x&~x [substitute 0xffff for 0x10000-1] ((((dbytes of x swapped)&(~(0xffff)))>>(0x10))|(((((x&(~(0xffff)))>>(0x10))|((x&(0xffff))<<(0x10)))&(0xffff))<<(0x10)))?x|~x:x&~x [substitute 0xffff0000 for ~0xffff] ((((dbytes of x swapped)&(0xffff0000))>>(0x10))|(((((x&(0xffff0000))>>(0x10))|((x&(0xffff))<<(0x10)))&(0xffff))<<(0x10)))?x|~x:x&~x [(dbytes of x swapped)&(0xffff0000) is zeroing the bottom half of the swapped halves of x; the original bottom half of x is now the top.] (((bottom 16 bits of x left shifted 16 bits)>>(0x10))|(((((x&(0xffff0000))>>(0x10))|((x&(0xffff))<<(0x10)))&(0xffff))<<(0x10)))?x|~x:x&~x [shift the bottom 16 bits of x back to their original location.] ((x with top 16 bits zeroed)|(((((x&(0xffff0000))>>(0x10))|((x&(0xffff))<<(0x10)))&(0xffff))<<(0x10)))?x|~x:x&~x [x&(0xffff0000) = x with bottom 16 bits zeroed; x&(0xffff) = x with top 16 bits zeroed] ((x with top 16 bits zeroed)|(((((x with bottom 16 bits zeroed)>>(0x10))|((x with top 16 bits zeroed)<<(0x10)))&(0xffff))<<(0x10)))?x|~x:x&~x [(x with bottom 16 bits zeroed)>>(0x10) = top 16 bits of x right-shifted 16 bits; (x with top 16 bits zeroed)<<(0x10) = bottom 16 bits of x left-shifted 16 bits] ((x with top 16 bits zeroed)|((((top 16 bits of x right-shifted 16 bits)|(bottom 16 bits of x left-shifted 16 bits))&(0xffff))<<(0x10)))?x|~x:x&~x [(top 16 bits of x right-shifted 16 bits)|(bottom 16 bits of x left-shifted 16 bits) = dbytes of x swapped, by same reasoning as above.] ((x with top 16 bits zeroed)|(((dbytes of x swapped)&(0xffff))<<(0x10)))?x|~x:x&~x [(dbytes of x swapped)&(0xffff) is zeroing the top half of the swapped halves of x; the original top half of x is now the bottom.] ((x with top 16 bits zeroed)|((top 16 bits of x right-shifted 16 bits)<<(0x10)))?x|~x:x&~x [(top 16 bits of x right-shifted 16 bits)<<(0x10) is undoing the right-shift.] ((x with top 16 bits zeroed)|(x with bottom 16 bits zeroed))?x|~x:x&~x [(x with top 16 bits zeroed)|(x with bottom 16 bits zeroed) = x] (x)?x|~x:x&~x [x|~x = all bits 1 = 0xffffffff; x&~x = 0] (x)?0xffffffff:0