Saturday, June 19, 2010

Bitwise Operator



This is what I learned about bitwise operators the other day (I set it up in a table so that I can remember what goes where)







































Operator
Syntax
Example
Bitwise Not ~a ~0111 = 1000
Bitwise OR a | b 0111 | 0000 = 0111
Bitwise And a & b 0111 & 1111 = 0111
Bitwise XOR a ^ b 0111 | 1111 = 1000
Bitwise Shift Left a << 2 0111 = 1100
Bitwise Shift Right a >> 2 0111 >> 2 = 0001
Bitwise Shift Right a >> 2 1000 >> 2 = 1110


*Right shift depends on sign and unsigned, unsigned always put preceding number(s) as 0, if it is signed, it depends on if the first number is 1 or 0, if it is 1 then the preceding number(s) become 1
*(I hope I copied it right)*

No comments:

Post a Comment