Why “010” equals 8?

前端 未结 5 518
予麋鹿
予麋鹿 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条回答
  •  猫巷女王i
    2021-01-18 01:08

    Any number in Java which fulfill the below Conditions - A. number Should have three or More Digital B.Number should Start with 0. If above Condition are true then number treated as Octal_Base (8) Number. Therefore, 010=(8^2)*0+(8^1)*1+(8^0)*0=64*0+8*1+1*0=8 So, 010=8

提交回复
热议问题