fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11. private static final int MODE_SHIFT = 30;
  12. private static final int MODE_MASK = 0x3 << MODE_SHIFT;
  13. public static final int UNSPECIFIED = 0 << MODE_SHIFT;
  14. public static final int EXACTLY = 1 << MODE_SHIFT;
  15. public static final int AT_MOST = 2 << MODE_SHIFT;
  16.  
  17. public static void main (String[] args) throws java.lang.Exception
  18. {
  19. int measureSpec = 0x7fffffff;
  20. int measureSpec2 = 0x40000100;
  21.  
  22. displayMeasureSpecInfos( measureSpec );
  23. displayMeasureSpecInfos( measureSpec2 );
  24.  
  25. }
  26.  
  27. private static void displayMeasureSpecInfos( int spec ) {
  28. System.out.println( Integer.toHexString(spec) );
  29. System.out.println("Spec is UNSPECIFIED "+ (getMode(spec) == UNSPECIFIED));
  30. System.out.println("Spec is EXACTLY "+ (getMode(spec) == EXACTLY));
  31. System.out.println("Spec is AT_MOST "+ (getMode(spec) == AT_MOST));
  32. System.out.println( "Measure is " + getSize(spec) );
  33. System.out.println( "-----" );
  34. }
  35.  
  36. public static int getMode(int measureSpec) {
  37. return (measureSpec & MODE_MASK);
  38. }
  39.  
  40. public static int getSize(int measureSpec) {
  41. return (measureSpec & ~MODE_MASK);
  42. }
  43. }
Success #stdin #stdout 0.06s 380160KB
stdin
Standard input is empty
stdout
7fffffff
Spec is UNSPECIFIED false
Spec is EXACTLY true
Spec is AT_MOST false
Measure is 1073741823
-----
40000100
Spec is UNSPECIFIED false
Spec is EXACTLY true
Spec is AT_MOST false
Measure is 256
-----