What is the difference between the two: BigInteger.valueOf (10000) and BigInteger.valueOf (0010000)?

I worked with one problem and came across this. What's happening:

when we use this: BigInteger.valueOf(10000) it gives a value of 10000

But

when we use this BigInteger.valueOf(0010000) , it gives a value of 4096

What is the difference between the two?

+6
source share
3 answers

0010000 is an octal literal. This has nothing to do with BigInteger - it's just whole Java literals ( JLS 3.10.1 ):

 System.out.println(10000); // 10000 System.out.println(0010000); // 4096 

From JLS:

The decimal digit is either a single ASCII digit 0 representing an integer zero, or consisting of an ASCII digit from 1 to 9, followed by one or more ASCII digits from 0 to 9, alternating with underscores representing a positive integer.

...

The octal digit consists of the ASCII digit 0, followed by one or more ASCII digits from 0 to 7, alternating with underscores, and can represent a positive, zero, or negative integer.

+12
source

The second is an integer in the octal system, the first in decimal, which causes the difference

+2
source

this takes a decimal literal as a parameter

 BigInteger.valueOf(10000) 

and it takes an octal literal as a parameter

BigInteger.valueOf(0010000) because it starts at 0

so you technically transmit 2 different numbers

  • 10,000

and

  1. 4096
+2
source

Source: https://habr.com/ru/post/1011640/


All Articles