sign int i = 0x81111111; i = (i >> 31) | (-i >>> 31); System.out.println( i ); reserve highest 1 int i = 0x88000088; i |= (i >> 1); i |= (i >> 2); i |= (i >> 4); i |= (i >> 8); i |= (i >> 16); i -= (i >>> 1); System.out.printf( "0x%X%n", i ); reserve lowest 1 int i = 0x88000088; i &= -i; System.out.printf( "0x%X%n", i ); number of leading 0 int i = 0x88000088; int n = 0; if (i >>> 16 == 0) { n += 16; i <<= 16; } if (i >>> 24 == 0) { n += 8; i <<= 8; } if (i >>> 28 == 0) { n += 4; i <<= 4; } if (i >>> 30 == 0) { n += 2; i <<= 2; } if (i >>> 31 == 0) { n += 1; i <<= 1; } if (i == 0) n++; // n -= i >>> 31; System.out.println( n ); number of 1 int i = 0x81111111; i = ((i&0xAAAAAAAA) >>> 1) + (i&0x55555555); i = ((i&0xCCCCCCCC) >>> 2) + (i&0x33333333); i = ((i&0xF0F0F0F0) >>> 4) + (i&0x0F0F0F0F); i = ((i&0xFF00FF00) >>> 8) + (i&0x00FF00FF); i = ((i&0xFFFF0000) >>> 16) + (i&0x0000FFFF); System.out.println( i ); reverse order int i = 0x11111111; i = ((i&0xAAAAAAAA)>>>1) | ((i&0x55555555)<<1); i = ((i&0xCCCCCCCC)>>>2) | ((i&0x33333333)<<2); i = ((i&0xF0F0F0F0)>>>4) | ((i&0x0F0F0F0F)<<4); i = ((i&0xFF00FF00)>>>8) | ((i&0x00FF00FF)<<8); i = ((i&0xFFFF0000)>>>16) | ((i&0x0000FFFF)<<16); System.out.printf( "0x%X%n", i );翻译代码
时间: 2024-03-28 09:39:21 浏览: 133
这是一些关于位运算的Java代码。下面是每个代码段的翻译:
1.将i初始化为0x81111111,然后对i进行位运算,将i的最高位和最低位进行保留,并输出i的值。
2.将i初始化为0x88000088,然后对i进行位运算,将i的最高位进行保留,并输出i的值。
3.将i初始化为0x88000088,然后对i进行位运算,将i的最低位进行保留,并输出i的值。
4.将i初始化为0x88000088,然后对i进行位运算,计算i的前导零的数量,并输出这个数量。
5.将i初始化为0x81111111,然后对i进行位运算,计算i中1的数量,并输出这个数量。
6.将i初始化为0x11111111,然后对i进行位运算,将i的二进制位按照相反的顺序排列,并输出i的值。
相关问题
帮我写注释练习题: // 1. int i = 3; i = i++; System.out.prinltn(“i = ” + i); // 2. int i = 3; i = ++i; System.out.println(“i = ” + i); // 3. int i = 3; int a = i++ + i++ + i++; int b = ++i + ++i + ++i; System.out.println(“i = ” + i); System.out.println(“a = ” + a); System.out.println(“b = ” + b); // 4. int i = 5; i++; System.out.println(“i = ” + i); ++i; System.out.println(“i = ” + i); int a = ++i; System.out.println(“a = ”+ a); a = a++; System.out.println(“a = ” + a); a = ++a; System.out.println(“a = ” + a); // 5. int m = 3; int n = 2 * ++m; System.out.println(“n = ”+ n); public class _07AddAdd { public static void main(String[] args) { // 声明一个int类型变量a,赋值1 int a = 1; int b = 2; // a++: 先赋值再自增 ++a:先自增再赋值 int c = a++ + ++a + b--; int d = c++ + c-- + a++ + ++b; // a = ? b = ? c = ? d = ? System.out.println("a = " + a);// a = 4 System.out.println("b = " + b);// b = 2 System.out.println("c = " + c);// c = 6 System.out.println("d = " + d);// d = 18 } }
题目1:
int i = 3; // 声明变量i,并赋值为3
i = i; // 将i的值赋给i本身,这一步没有任何意义
System.out.prinltn("i = " i); // 输出i的值
题目2:
int i = 3; // 声明变量i,并赋值为3
i = i; // 将i的值赋给i本身,这一步没有任何意义
System.out.println("i = " i); // 输出i的值
题目3:
int i = 3; // 声明变量i,并赋值为3
int a = i i i; // 将i的值乘3赋给a
int b = i i i; // 将i的值乘3赋给b
System.out.println("i = " i); // 输出i的值
System.out.println("a = " a); // 输出a的值
System.out.println("b = " b); // 输出b的值
题目4:
int i = 5; // 声明变量i,并赋值为5
i ; // 这一步没有任何意义,单独使用变量名不会有任何输出
System.out.println("i = " i); // 输出i的值
i; // 这一步没有任何意义,单独使用变量名不会有任何输出
System.out.println("i = " i); // 输出i的值
int a = i; // 将i的值赋给a
System.out.println("a = " a); // 输出a的值
a = a ; // 将a的值赋给a本身,这一步没有任何意义
System.out.println("a = " a); // 输出a的值
a = a; // 将a的值赋给a本身,这一步没有任何意义
int i =1;while(i <5){for(int j=i;j>1;j- -)System.out.print(j+“”);System.out.println(“****”)i++;}
As an AI language model, I cannot execute the code above as it contains errors. Here is a corrected version of the code:
int i = 1;
while (i < 5) {
for (int j = i; j > 1; j--) {
System.out.print(j + " ");
}
System.out.println("****" + i);
i++;
}
The code above will print the following output:
****1
2 ****2
3 2 ****3
4 3 2 ****4
The code uses a nested loop to print a triangular pattern with decreasing numbers from the current row number to 1, followed by four asterisks and the row number. The outer loop controls the number of rows to print, and the inner loop prints the numbers in each row.
阅读全文