Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is 00 an integer or octal in Java?

Is

00, 000, or 000...

an integer in Java? Or is it an octal? If is it an octal is

001 or 0005

an octal?

like image 829
stcho Avatar asked Jun 04 '14 07:06

stcho


People also ask

Is 0 octal or decimal?

If an integer constant begins with 0x or 0X, it is hexadecimal. If it begins with the digit 0, it is octal. Otherwise, it is assumed to be decimal.

What is octal integer in Java?

Octal is a number system where a number is represented in powers of 8. So all the integers can be represented as an octal number. Also, all the digit in an octal number is between 0 and 7. In java, we can store octal numbers by just adding 0 while initializing. They are called Octal Literals.

What is considered an integer in Java?

An integer in Java is a memory location that can hold an integer, a positive or negative non-decimal number. It is denoted by the keyword, 'int'.

Can integer start with 0 in Java?

Zeros are ignored at the start of an int . If you need the zeros to be displayed, store the number as a String instead. If you need to use it for calculations later, you can convert it to an int using Integer.


2 Answers

All are integers, but...

1  is decimal
0  is decimal
01 is octal
00 is octal

From Java Language Specification (emphasis mine):

Note that octal numerals always consist of two or more digits; 0 is always considered to be a decimal numeral - not that it matters much in practice, for the numerals 0, 00, and 0x0 all represent exactly the same integer value.

like image 99
Christian Tapia Avatar answered Sep 29 '22 10:09

Christian Tapia


Number literal representation examples in Java will give you the answer:

int decimal = 100;
int octal = 0144;
int hex = 0x64;
int binary = 0b1100100;

So 00, 000 and 0000 are all octal(base-8) integers.

like image 33
Juvanis Avatar answered Sep 29 '22 10:09

Juvanis