This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Range of Octals

 
Richa Sharma
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What is the max numbers i can store as octal. Is it the same as 32 bit integers unsigned?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sagar
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richa Sharma wrote:Thanks Sagar

You're welcome
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15437
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
-0x80000000 to 0x7FFFFFFF (hexadecimal)
 
Sanjay Singhaniya
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 21387
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Guys
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic