+ 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.
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'
+ 4
Convert a control character into its equivalent printable keystroke:
Ctrl-A OR 64 = 'A' ... Ctrl-Z OR 64 = 'Z'
+ 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
+ 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.
+ 3
Seniru try implementing Huffman Encoding if you are looking for an interesting exercise in bitwise operations.
+ 1
ᏃᎪᏟᏦ✰ haha I have reached my limit. Can you summarise what was there here, if you can?
+ 1
Brian thanks for the suggestion!
0
Brian thanks for posting those tricks. Do you know any large scale application that use these bit operations