(String[] args)
| 26 | } |
| 27 | |
| 28 | public static void main(String[] args) { |
| 29 | // 非负数 |
| 30 | int a = 78; |
| 31 | System.out.println(a); |
| 32 | printBinary(a); |
| 33 | System.out.println("===a==="); |
| 34 | // 负数 |
| 35 | int b = -6; |
| 36 | System.out.println(b); |
| 37 | printBinary(b); |
| 38 | System.out.println("===b==="); |
| 39 | // 直接写二进制的形式定义变量 |
| 40 | int c = 0b1001110; |
| 41 | System.out.println(c); |
| 42 | printBinary(c); |
| 43 | System.out.println("===c==="); |
| 44 | // 直接写十六进制的形式定义变量 |
| 45 | // 0100 -> 4 |
| 46 | // 1110 -> e |
| 47 | // 0x4e -> 01001110 |
| 48 | int d = 0x4e; |
| 49 | System.out.println(d); |
| 50 | printBinary(d); |
| 51 | System.out.println("===d==="); |
| 52 | // ~、相反数 |
| 53 | System.out.println(a); |
| 54 | printBinary(a); |
| 55 | printBinary(~a); |
| 56 | int e = ~a + 1; |
| 57 | System.out.println(e); |
| 58 | printBinary(e); |
| 59 | System.out.println("===e==="); |
| 60 | // int、long的最小值,取相反数、绝对值,都是自己 |
| 61 | int f = Integer.MIN_VALUE; |
| 62 | System.out.println(f); |
| 63 | printBinary(f); |
| 64 | System.out.println(-f); |
| 65 | printBinary(-f); |
| 66 | System.out.println(~f + 1); |
| 67 | printBinary(~f + 1); |
| 68 | System.out.println("===f==="); |
| 69 | // | & ^ |
| 70 | int g = 0b0001010; |
| 71 | int h = 0b0001100; |
| 72 | printBinary(g | h); |
| 73 | printBinary(g & h); |
| 74 | printBinary(g ^ h); |
| 75 | System.out.println("===g、h==="); |
| 76 | // 可以这么写 : int num = 3231 | 6434; |
| 77 | // 可以这么写 : int num = 3231 & 6434; |
| 78 | // 不能这么写 : int num = 3231 || 6434; |
| 79 | // 不能这么写 : int num = 3231 && 6434; |
| 80 | // 因为 ||、&& 是 逻辑或、逻辑与,只能连接boolean类型 |
| 81 | // 不仅如此,|、& 连接的两侧一定都会计算 |
| 82 | // 而 ||、&& 有穿透性的特点 |
| 83 | System.out.println("test1测试开始"); |
| 84 | boolean test1 = returnTrue() | returnFalse(); |
| 85 | System.out.println("test1结果," + test1); |
nothing calls this directly
no test coverage detected