Bit-wise operation tricks [duplicate]
Possible Duplicate:
What USEFUL bitwise operator code tricks should a developer know about?
Hi,
What are some neat tricks with using bit-wise operations. I know that unless you're programming in C you won't have much encounters with operating on bit level. Nonetheless, there are some neat tricks that you can apply in even higher level languages. Here are a few that I already know.
- bit mask: Can hold a collection of boolean values
- XOR Swap: Swap 2 values in place without a third variable
- XOR Linked List: Create a doubly linked list with each node only hold one address value
What are some others?
find whether a number is odd or not
(number & 1)
精彩评论