How bitwise operations are helpful in coding | Sololearn: Learn to code for FREE!


How bitwise operations are helpful in coding

I know different bitwise operations, like AND, OR, NOT, NAND, LSHIFT, etc. I know that AND, OR and things like that will be helpful in conditionals and some calculations. But what about others? I have seen that people are using them hugely in their codes to do things like compressing, packing and color manipulations. Also I found some interesting tricks that could be done with them from google (like checking if a number is odd or even) But what else can I do with them? Also an example would be helpful.

3/4/2020 1:45:24 PM


9 Answers

New Answer


Toggle between uppercase and lowercase ASCII characters: 'A' XOR 32 = 'a' ... 'Z' XOR 32 = 'z' 'a' XOR 32 = 'A' ... 'z' XOR 32 = 'Z'


Convert a control character into its equivalent printable keystroke: Ctrl-A OR 64 = 'A' ... Ctrl-Z OR 64 = 'Z'


Fastest way to find positive integer modulo if the modulus is a power of two: X AND 7 = X MOD 8 X AND 31 = X MOD 32


Seniru I have developed a number of large scale applications that depend on bitwise operations in portions of the code. But scale of the application is irrelevant. Use bitwise operations if they are appropriate to help you meet the requirements.


Seniru try implementing Huffman Encoding if you are looking for an interesting exercise in bitwise operations.


ᏃᎪᏟᏦ✰ haha I have reached my limit. Can you summarise what was there here, if you can?


Brian thanks for the suggestion!


Brian thanks for posting those tricks. Do you know any large scale application that use these bit operations