xor (^) is commonly used in encryption schemes, since xor'ing a value
against the same number twice gives you the original value. i.e., 255^1
gives you 254, and 254^1 gives you back the original 255. The shift
operators >> and << are also used to pack data and are used in many
encryption or base-conversion (decimal to hexadecimal numbers for instance)
schemes.
An old programmer's trick is to use << and >> to multiply or divide an
integer by a power of 2 (for instance (x >> 1) divides x by 2, and (x << 4)
multiplies x by 16). The shift operators are based on assembly language
instructions that generally operate much faster (fewer clock cycles) than
the equivalent integer multiply and divide instructions. So they can be
useful in other areas besides complex calculations.
Hope that helps,
Michael C.
"Chua Wen Ching" <ch************@nospam.hotmail.com> wrote in message
news:1D**********************************@microsof t.com... Hi,
I had some beginner questions. Do we need Shift << >> or Logical AND
OR XOR operator in our daily programming?
I am not sure why i need to use it? I had some samples of c# codes
using it.
Can someone share their experiences why someone should use those
operators and what type of scenarios?
Any good snippets and example?
Thanks.
--
Regards,
Chua Wen Ching :)