Why “010” equals 8?

前端 未结 5 476
予麋鹿
予麋鹿 2021-01-18 00:30

My simple question is why:

System.out.println(010|4);

prints \"12\"? I understand bitwise OR operator but why \"010\" equals 8? It\'s defin

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-18 01:09

    That is because java takes it as an octal literal and hence produces 12. Try System.out.println(10|4) and the result is 14. Because this time it is taken as decimal literal.

提交回复
热议问题