November 6th, 2013, 03:06 PM

Please help me understand an assignment question. PLEASE DO NOT ANSWER THE QUESTION!
I have an assignment for my computer science course and I do not understand what the question is asking of me. If you understand can you please explain what the question wants me to do.
any help is greatly appreciated!!
Here is the question.
Introduction (I inserted this incase you do not understand the question. Question is below in Quote tags)
A hypothetical multitouch device, the TouchTab 2020, is able to handle touch input from up to three fingers simultaneously. Its lowlevel drivers provide the x and y position values for each touch and a pressure.
Your task is to take the values reported by the hardware and produce higherlevel data structures representing multitouch traces. A multitouch trace will be given as an array of long values, with each long encoding up to three touch points at a given instant in time. Since the input touches are sampled at a known freqency, the array then provides the sequence of positions of the touches as they move over time.
The touches at each instant are encoded in the 64 bits of a long value as follows. At each moment, there are n = 0,1,2 or 3 touches. The x, y and pressure for the touches are given as (x1,y1,p1), (x2,y2,p2) and (x3,y3,p3) when the touches are present. The device is wider than it is tall, so each x value is reported as a 9 bit integer (between 0 and 511) and each y value is reported as an 8 bit integer (between 0 and 255). The pressures are reported as 3 bit values (between 0 and 7). The number of points reported, n, will be between 0 and 3 and is represented with 2 bits. The bits are stored in the long integer out as follows:
bits 0 1, n
bits 2 3, reserved
bits 412, x1
bits 1320, y1
bits 2129, x2
bits 3037, y2
bits 3846, x3
bits 4754, y3
bits 5557, p1
bits 5860, p2
bits 6163, p3.
For each of the questions below, hand in
an implementation
documentation of the class and each methods
test output
Question 1. Static Methods and Bit Fiddling (30 points)
Create a class called MultitouchStatusOperations that has no data fields and provides only static methods to do lowlevel bit operations on long integers, as follows.
The class should have four operations, each encoding a number of reported points. There is one method to construct long for 0 points, one for 1 point, one for 2 points and one for 3 points.
public static long makeStatusWord();
public static long makeStatusWord(int x1, int y1, int p1);
public static long makeStatusWord(int x1, int y1, int p1,
int x2, int y2, int p2);
public static long makeStatusWord(int x1, int y1, int p1,
int x2, int y2, int p2,
int x3, int y3, int p3);
The class should also have operations to extract the number of encoded points as well as each of the x, y and pressure values:
public static int numberOfPoints(long statusWord);
public static int x1(long statusWord);
public static int y1(long statusWord);
public static int x2(long statusWord);
public static int y2(long statusWord);
public static int x3(long statusWord);
public static int y3(long statusWord);
You should write a test program that uses these methods and convincingly shows they are working properly for the required ranges of inputs. You will find it useful in testing to know that long integer values can be written using an "L" suffix, e.g. 1L << 40 or 5000000000000L.
November 6th, 2013, 03:39 PM

Do you know the basic thing it ask you to do:
 Create a class?
 How static method is working?
Have you look at and understand how Bitwise and Bit Shift Operators work?
The idea is that you have some method that should add or retreive the information about the touch using a longtyped value.
For example:
Code:
public static long makeStatusWord(int x1, int y1, int p1);
should change a long value where you have modified the bit value related to x1 (412), y1 (1320) and p1 (5557).
Code:
public static int x1(long statusWord);
should return the value stored in the bitrange of x1 (412).
November 6th, 2013, 03:47 PM

MrFujin thank you so much for a quick reply. I will definitely suggest this website to friends.
I do understand bitshifting I think. I created this as a quick template.
Code:
public static int n = 0; // number of fingers touching. 0  3 (1 bit reserved?)
public static int x1 = 0; // 9 bit integer (0  511) because x is longer than y
public static int x2 = 0;
public static int x3 = 0;
public static int y1 = 0; // 8 bit integer (0  255)
public static int y2 = 0;
public static int y3 = 0;
public static int p1 = 0; // 3 bit VALUE (0  7)
public static int p2 = 0;
public static int p3 = 0;
public static int res = 0; //reserved bits
public static long value = 0, //how many points being pressed at once.
R = value (n << 1)(res <<2)(x1 <<4)(y1 <<13)(x2 <<21)(y2 << 30)(x3 << 38)(y3 << 47)(p1 << 55)(p2 << 58)(p3 <<61);
Assuming that the template is correct. I think I have completed the first part, I am confused about returning the value stored in the bitrange of x1 (412).
Since I have set the long value, could I not just return the int x1? as the program will be modifying x1.
Thanks once again for helping.
Last edited by kinglewey1st; November 6th, 2013 at 03:48 PM.
Reason: spelling
November 6th, 2013, 04:11 PM

Think you overlooked this part:
that has no data fields
You are not supposed/allowed to create those variables that can be accessed from any function.
Each function only has the data provided to it through its arguments.
November 6th, 2013, 04:56 PM

Originally Posted by MrFujin
Think you overlooked this part:
that has no data fields
You are not supposed/allowed to create those variables that can be accessed from any function.
Each function only has the data provided to it through its arguments.
Ok, so am I correct in creating a method like this
Code:
public static long makeStatusWord(int x1, int y1, int p1, int x2, int y2, int p2){
long value = 2;
value =(x1 = 4<< 12)(x2 = 21<<29)(y1 = 13<<20)(y2 = 30<<37)(p1 = 55 << 57)(p2 = 58<<60);
return value;
}
Sorry for all the questions, this assignment just seemed very vague too me.
November 6th, 2013, 05:54 PM

Setting value to 2 does not make sense.
The variable should not be assigned with new value, but used to create the long:
Code:
value =(x1 << 12)(x2 <<29)(y1 <<20)(y2 <<37)(p1 << 57)(p2 <<60);
You should also look at the bit shifting as you want to look at their start position.
E.g. x2 start at bit 21 which means it should be shifted 20 bits ahead (x2<<20).
November 7th, 2013, 05:50 PM

Ok, I had a sleep on it. I definitely needed to re read over bitWise again. I managed to create the part which checks how many fingers are touching using the long value.
E.G
Code:
if(value == 0xEFD9C3C0){
System.out.println("Three Fingers are touching the panel.");
}
Now to check the value of x1, I should create an Int and then put the long value 4<<12 as the int?
Something like this (untested just hypothesizing)
Code:
int result = 0;
result = (value = 4<<12);
November 8th, 2013, 04:05 PM

Is anyone able to confirm what i'm doing is correct?
November 8th, 2013, 05:40 PM

Where did you get 0xEFD9C3C0 from?
To get the number of finger touches, you should read the first two bits in the long value. In the number above, the value of the first two bits is 0 (no touches)
To get the value of x1, you should read the value from bit 412 from the passed long value.
This can be done using >> and then a bitwise AND.
November 8th, 2013, 07:54 PM

Originally Posted by MrFujin
Where did you get 0xEFD9C3C0 from?
To get the number of finger touches, you should read the first two bits in the long value. In the number above, the value of the first two bits is 0 (no touches)
To get the value of x1, you should read the value from bit 412 from the passed long value.
This can be done using >> and then a bitwise AND.
I got the number using this method breaking down 16 base long numbers.
Code:
// value for 3 fingers pressed checked using command System.out.println(Long.toBinaryString(value)) is...
// 1111111111111111111111111111111111101111110110011100001111000000
// 1111111111111111111111111111111111101111110110011100001111000000 Broken down using a 16 base system
// 15(F) 15(F)15(F)15(F)15(F)15(F)15(F)15(F)14(E)15(F)13(D) 9 12(C) 3 12(C) 0  Add 0x to tell java it's 16 base system.
// result = 0xFFFFFFFFEFD9C3C0
if(value == 0xFFFFFFFFEFD9C3C0L){
System.out.println("Three Fingers are touching the panel.");
number = 3;
}
It seems to work correctly when I call them.
With the getting the value of X1
I can get it to show up doing this.
Code:
public static int x1(long statusWord){ // Extracting the points of x1.
int x1 = 0;
x1 = (int) (value & 0xFFL); // X (an integer) become the binary at position 04 (F represents 4)
System.out.println("The value of X is " + x1); // Prints the value of X which is now the binary at position 04
value = (value & 0xFFL) >> 4; // Takes the value of x1 at position 48 and moves it to position 04
x1 = (int) (value & 0xFFL); // X (an integer) become the binary at position 04 (F represents 4)
System.out.println("The real original value of x before moved is " + x1); // Prints the value of X which is now the binary at position 04
return x1; //returns the original value of x (Did not know EXACTLY what the assignment asked for. If it wants full value of x remove 3 lines above.
}
I feel that's a hell of alot of work though.
Edit just saw your comment about the & function. Looking into it now.
November 8th, 2013, 09:21 PM

I assumed the number of (bit 01) was in the rightmost position:
Code:
1111111111111111111111111111111111101111110110011100001111000000
based on how you wanted to create the long value:
Code:
value =(x1 = 4<< 12)(x2 = 21<<29)(y1 = 13<<20)(y2 = 30<<37)(p1 = 55 << 57)(p2 = 58<<60);
Something i have misunderstood?
Where did you get this number from? something you made up yourself, or?
November 9th, 2013, 10:59 AM

Originally Posted by MrFujin
I assumed the number of (bit 01) was in the rightmost position:
Code:
1111111111111111111111111111111111101111110110011100001111000000
based on how you wanted to create the long value:
Code:
value =(x1 = 4<< 12)(x2 = 21<<29)(y1 = 13<<20)(y2 = 30<<37)(p1 = 55 << 57)(p2 = 58<<60);
Something i have misunderstood?
Where did you get this number from? something you made up yourself, or?
I Got the large binary number from (Long.toString() function.
then I used a hexidecimal 16 base system breaking down the 0's and 1's into groups of 4. then I worked out what each number was
0001 = 1
0011 = 3
0100 = 4
1000 = 8
1100 = C
that gave me my answer.