< ( ) int, int 0 , , int, , , , 31- ( 0 ) 1 - <, , , int.
2 1,2,4,8,16,32,......, 1073741824 int.
'1' .
, | ( ) 2, "1" "1" .
, 8 (1000) 1 3, 2 (10) 1 1, | () 1010 , , 1 3 1.
, , , "1" .
-
static int test0= 1;
static int test1= 2;
static int test2= 4;
static int test3= 8;
static int test4= 16;
static int test5= 32;
static int test6= 64;
int[] result;
int[] decision(int flags){
char[] x=Integer.toBinaryString(flags).toCharArray();
result=new int[x.length];
for(int i=x.length-1,j=0,k=0;i>=0;i--)
switch (x[k++]){
case '0':
break;
case '1':
if(i==0){
result[j++]=-1;
break;
}
result[j++]=i;
};
return result;
}
/*
, , {6,3,1,0,0,0}, , test6, test3 test1 or-ed ( (test6 | test3 | test1)).
*/
Thanks to the above two answers, I had a question about how the methods you were talking about work, I got an answer from the two above answers. The actual implementation works as shown in the previous two answers.