?? binarytest.java
字號:
// operators/BinaryTest.java
// TIJ4 Chapter Operators, Exercise 10, page 112
/* Write a program with two constant values, one with alternating binary ones and
* zeroes, with a zero in the least-significant digit, and the second, also
* alternating, with a one in the least-significant digit (hint: It's easiest to
* use hexadecimal constants for this). Take these two values and combine them in
* all possible ways using the bitwise operators, and display the results using
* Integer.toBinaryString().
*/
import org.greggordon.tools.*;
public class BinaryTest {
public static void main(String[] args) {
int i = 1 + 4 + 16 + 64;
int j = 2 + 8 + 32 + 128;
P.rintln("i = " + Integer.toBinaryString(i));
P.rintln("j = " + Integer.toBinaryString(j));
P.rintln("i & j = " + Integer.toBinaryString(i & j));
P.rintln("i | j = " + Integer.toBinaryString(i | j));
P.rintln("i ^ j = " + Integer.toBinaryString(i ^ j));
P.rintln("~i = " + Integer.toBinaryString(~i));
P.rintln("~j = " + Integer.toBinaryString(~j));
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -