+ 2

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.

4th Mar 2020, 1:45 PM
Seniru
Seniru - avatar
8 Respostas
+ 4
Toggle between uppercase and lowercase ASCII characters: 'A' XOR 32 = 'a' ... 'Z' XOR 32 = 'z' 'a' XOR 32 = 'A' ... 'z' XOR 32 = 'Z'
9th Mar 2020, 11:52 AM
Brian
Brian - avatar
+ 4
Convert a control character into its equivalent printable keystroke: Ctrl-A OR 64 = 'A' ... Ctrl-Z OR 64 = 'Z'
9th Mar 2020, 12:01 PM
Brian
Brian - avatar
+ 4
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
9th Mar 2020, 12:11 PM
Brian
Brian - avatar
+ 3
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.
9th Mar 2020, 2:12 PM
Brian
Brian - avatar
+ 3
Seniru try implementing Huffman Encoding if you are looking for an interesting exercise in bitwise operations.
9th Mar 2020, 5:50 PM
Brian
Brian - avatar
+ 1
ᏃᎪᏟᏦ✰ haha I have reached my limit. Can you summarise what was there here, if you can?
4th Mar 2020, 2:13 PM
Seniru
Seniru - avatar
+ 1
Brian thanks for the suggestion!
10th Mar 2020, 12:39 PM
Seniru
Seniru - avatar
0
Brian thanks for posting those tricks. Do you know any large scale application that use these bit operations
9th Mar 2020, 1:50 PM
Seniru
Seniru - avatar