BBC (Brian's Boot Camp)

Not to be confused with the British Broadcasting Corporation, the BBC will focus on Brian's fast paced journey of the mastery of the Java programming language.

Wednesday, September 27, 2006

Masking

How about a nice intro to masking? Write the body of this function:


public int extractBit(int num, int pos);


This function should return the value of the bit of "num" at postion "pos".

For example: extractBit(5, 0) would return one, whereas extractBit(16, 2) would return zero.

Hint: Start by looking at how bitwise & works.

0 Comments:

Post a Comment

<< Home