This week's book giveaways are in the Refactoring and Agile forums.We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!

# Range of Octals

Richa Sharma
Ranch Hand
Posts: 47

What is the max numbers i can store as octal. Is it the same as 32 bit integers unsigned?

Sagar Rohankar
Ranch Hand
Posts: 2906
1
Richa Sharma wrote:
Is it the same as 32 bit integers unsigned?

Java dosen't support unsigned int types !
Richa Sharma wrote:
What is the max numbers i can store as octal.

This is the range for 32 bit int
–2,147,483,648 to 2,147,483,647
So you can see, the maximum int type is 2,147,483,647(decimal) and convert it into Octal

Richa Sharma
Ranch Hand
Posts: 47
Thanks Sagar

Sagar Rohankar
Ranch Hand
Posts: 2906
1
Richa Sharma wrote:Thanks Sagar

You're welcome

Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Octal is not a data type - it is just a different way to write down numbers, just like decimal and hexadecimal.

Data types have a range, for 32-bit integers the range is -2^31 to 2^31 - 1, which is:

-2147483648 to 2147483647 (decimal)
-020000000000 to 017777777777 (octal)

Sanjay Singhaniya
Greenhorn
Posts: 25
As Jesper Young correctly pointed out, you can represnt integer or long numbers in octal.
To represent a long number in octal; simply add L at the end of number literal.

For example,

Henry Wong
author
Marshal
Posts: 20889
75

Interestingly, these two assignments are actually legal in java...

This is because octal (and hex) were historically used for bit masks -- that Java allows you to actually assign all the bits, including the negative bit, as if it was an unsigned number.

Henry

Richa Sharma
Ranch Hand
Posts: 47
Thanks a lot Guys