#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    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 multi-touch device, the TouchTab 2020, is able to handle touch input from up to three fingers simultaneously. Its low-level 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 higher-level data structures representing multi-touch traces. A multi-touch 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 4-12, x1
    bits 13-20, y1

    bits 21-29, x2
    bits 30-37, y2

    bits 38-46, x3
    bits 47-54, y3

    bits 55-57, p1
    bits 58-60, p2
    bits 61-63, 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 low-level 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.
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,647
    Rep Power
    1945
    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 long-typed 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 (4-12), y1 (13-20) and p1 (55-57).

    Code:
    public static int x1(long statusWord);
    should return the value stored in the bit-range of x1 (4-12).
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0
    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 bit-range of x1 (4-12).
    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 02:48 PM. Reason: spelling
  6. #4
  7. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,647
    Rep Power
    1945
    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.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0
    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.
  10. #6
  11. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,647
    Rep Power
    1945
    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).
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0
    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);
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0
    Is anyone able to confirm what i'm doing is correct?
  16. #9
  17. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,647
    Rep Power
    1945
    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 4-12 from the passed long value.
    This can be done using >> and then a bitwise AND.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0
    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 4-12 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
    		// |1111|1111|1111|1111|1111|1111|1111|1111|1110|1111|1101|1001|1100|0011|1100|0000   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 0-4 (F represents 4)
    		System.out.println("The value of X is " + x1);  // Prints the value of X which is now the binary at position 0-4
    
    		value = (value & 0xFFL) >> 4;                  // Takes the value of x1 at position 4-8 and moves it to position 0-4
    		x1 = (int) (value & 0xFFL);                    // X (an integer) become the binary at position 0-4 (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 0-4
    		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.
  20. #11
  21. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,647
    Rep Power
    1945
    I assumed the number of (bit 0-1) was in the right-most 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?
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0
    Originally Posted by MrFujin
    I assumed the number of (bit 0-1) was in the right-most 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.

IMN logo majestic logo threadwatch logo seochat tools logo