Programming languages often come with various bit operators (e.g. bitwise left- and right shift, bitwise AND, OR, XOR...). These don't get used though very much, or at least such has my experience been. They are sometimes used in programming challenges or interview questions, or the solution migh require them, e.g.:Without using any equality operator, create a function which returns true when two values are equalWithout using a third variable, swap the value of two variablesThese then again, probably have few real world uses. I guess that they should be faster because they directly manipulate memory on a low level. Why are such found in most programming languages? Any real world use cases?
What are bit operators good for?
programming languages;operators;bitwise operators
No, they have many real-world applications, and are fundamental operations on computers.They are used for Juggling blocks of bytes around that don't fit in the programming languages data typesSwitching encoding back and forth from big to little endian.Packing 4 6bit pieces of data into 3 bytes for some serial or usb connectionMany image formats have differing amounts of bits assigned to each color channel.Anything involving IO pins in embedded applicationsData compression, which often does not have data fit nice 8-bit boundaries.\Hashing algorithms, CRC or other data integrity checks.EncryptionPsuedorandom number generationRaid 5 uses bitwise XOR between volumes to compute parity.Tons moreIn fact, logically, all operations on a computer ultimately boil down to combinations of these low level bitwise operations, taking place within the electrical gates of the processor.