Re:A Bit Overcomplicated
by karmanyaahm on Thursday August 05, 2021 @02:05PM
(#28077323)
One of the few positive and helpful posts in this thread. The anger and fighting seems to be invited much more. Welcome to the internet
If you are curious, bit shifting is essentially multiplication or division by 2. It is faster than doing the actual arithmetic.
Bitwise operators just perform logical bitwise and, or, xor operations on the bit representations of two numbers.
This is especially useful if you have mapped some data to binary 0-1 vectors and those operations are semantically meaningful for the representation.
Just as an example, you can calculate the Hamming distance between two 0-1 vectors by taking an XOR of their integer representations and then accumulating the 1s digits for all shifts (towards 0) of the XOR-ed value.