Bitwise operation use cases



This topic got me very, very hooked.
Would anyone be kind enough to list some scenarios of bitwise use cases?
I've read around on stack exchange about it being used to inject headers, error checking, flags, etc into frames. Was wondering if there were any other use cases besides data transmission and controlling hardware using old ports?

Thank you !

Need help understanding the purpose behind Overriding

The simplest use case is in multiplying by 2 ^ n where n > 0

x * 2 ** n == x << n

One use for masking is DIP switches where each switch is a bit in a register that goes toward control flow. Another would be for mapping access permissions in a single byte, rather than several.

When a file is compressed it is turned to a long string of bits instead of bytes. It could be applied to encryption, as well. both of these concepts are way over my head but if you are going down that road expect to see bitwise logic in use.

When mapping booleans such as a sieve, each bit can be representative of a number... The number of shifts left would be the number. This sort of sieve would be used to generate and detect very large primes. One kilobyte (2^10) has 8 * 2^10 bits (8192). This sieve could map primes in the range 0 to 8191 inclusive.

The list is probably quite long once we start investigating. These are just some off the top of my head.,_Programming,_Data_Representation_and_Practical_Exercise/Fundamentals_of_Programming/Logical_bitwise_operators


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.