For example, in PHP, how would I reverse the bits of the byte 11011111
to 11111011
?
Check the section on reversing bit sequences in Bit Twiddling Hacks. Should be easy to adapt one of the techniques into PHP.
While probably not practical for PHP, there's a particularly fascinating one using 3 64bit operations:
unsigned char b; // reverse this (8-bit) byte
b = (b * 0x0202020202ULL & 0x010884422010ULL) % 1023;