Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有人可以解释这个java按位运算符的行为吗?
System.out.println(010 | 4); // --> 12 System.out.println(10 | 4); // --> 14
谢谢!
第一个数字被解释为八进制。所以010 == 8。
010 == 8
从那开始,不难看出,
8d | 4d == 1000b | 0100b == 1100b == 12d
第二个数字被解释为十进制,产生
10d | 4d == 1010b | 0100b == 1110b == 14d
(其中d表示十进制数,b表示二进制数。)
d
b