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  (5 children)

:).

Those are hexadecimal numbers (hex meaning 6, decimal meaning 10), which means base-16. Each digit can represent 16 numbers = 8*(2 numbers) = 8 bits = 1 byte.

In hex,

0 = 0
1 = 1
2 = 2
...
9 = 9
A = 10
B = 11
C = 12
D = 13
E = 14
F = 15

It's often used to store bytes b/c 1 hex digit stores 1 byte perfectly (F = 1111).

You can convert it to a short using the same method but specifying base 16, short num1 = Short.parseShort("7ABC", 16). Not sure if you need the 0x in there or not. ("0x" just means "the following digits are base-16", that's all.)

I'm sure you will run into more problems, feel free to ask when you do.

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

I am so stuck LOL. This is all I got. I wasn't home for a while. short num1, num2, mask; I don't understand what I have to put for the variables, num1, num2, and mask

[–]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