⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 binarytest.java

📁 JAVA编程思想第四版英文原版习题答案. pdf原版的
💻 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 + -