0

I have a short question about Datatypes. Why do i get this kind of number if i put a leading 0 for a number that i declared to be a long-type? I just dont get what the zero is making to the number.

For example:

1010L -> 1010  
0101L -> 65
Kyrill96
  • 39
  • 4
  • This would be a good time to familiarize yourself with the documentation, http://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.10.1. The JLS rules all definitions Java. – Lew Bloch May 04 '17 at 16:32
  • Point: it's not a leading zero in a number, it's a leading zero in the representation of a number. – Lew Bloch May 04 '17 at 16:33

2 Answers2

0

In Java integer literals with a leading zero are treated as octal by the compiler.

0

The leading zero is telling the computer to interpret the number as an octal.

In octal, base eight, the first one represents 64 in base ten, and the last one represents 1:

64 + 1 = 65 (base 10).