Saturday, January 8, 2011

Bit Operation #8


100000
100000
------
011111

000000
000000
------
000000

100000
000000
------
000000

000100
000100
------
111011

100100
100100
------
011011

100100
000100
------
111011

010101
101010
------
000000

111111
111111
------
000000

// A function using bitwise operators for above results.
unsigned int f(unsigned int a, unsigned int b)
{
if (a & b)
{
return ~(a & b);
}
return 0;
}

No comments: