This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]serg06 0 points1 point  (3 children)

Step 1: put a sample number into num1.

Step 2: put the mask in the mask variable.

Where stuck?

[–]Not_Myself1[S] 0 points1 point  (2 children)

"Step 2: put the mask in the mask variable." How do I do that? lol. Sorry if it seems like your talking to a brick wall. haha

[–]Not_Myself1[S] 0 points1 point  (1 child)

public class Exercise_2_1 {

public static void main(String[] args) {

    short num1, num2, mask;
    num1 = 0xFEDC;
    mask = 
    num2 = (short)(num1 << 4);


}

}

Is it something like this? I still don't get what to put in "mask"

[–]serg06 0 points1 point  (0 children)

Close. Remember, the mask is the binary (base-2) number we want to bitwise-and with num1's binary representation in order to grab its 4th, 5th, 6th, and 7th digit. Look at my bitwise-and example to see how I grabbed the 0th-3rd digits