programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Tim Cooke
• Devaka Cooray
• Ron McLeod
• Jeanne Boyarsky
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Piet Souris
• Carey Brown
• Tim Holloway
Bartenders:
• Martijn Verburg
• Frits Walraven
• Himai Minh

# Literal values doubt

Ranch Hand
Posts: 117
• Number of slices to send:
Optional 'thank-you' note:
hello friends,

I have read that we can have upto 21 digits in an octal number, not including the leading zero.

Can anyone please tell me the maximum number that can be initialized for a variable in octal representation...

Ranch Hand
Posts: 1710
• Number of slices to send:
Optional 'thank-you' note:
Hi Raja,

I have read that we can have upto 21 digits in an octal number, not including the leading zero.

Can anyone please tell me the maximum number that can be initialized for a variable in octal representation...

The range is same, don't get confused with octal. 21 digit is the maximum accumulated number an octal number that can be assigned.
If you convert the 21 digit octal (the maximum) to decimal, it will come to the same range a long primitive can hold.

int : 32 bits
long: 64 bits

(0777777777777777777777) (octal maximum range "21 digits excluding 0")
=
=
(1111111111111111111111111111111111111111111111111111111111) (maximum range of 63 bits, a long can hold, excluding sign bit)

Thanks and Regards,
cmbhatt

[ April 07, 2007: Message edited by: Chandra Bhatt ]
[ April 07, 2007: Message edited by: Chandra Bhatt ]

Hardik Raja
Ranch Hand
Posts: 117
• Number of slices to send:
Optional 'thank-you' note:
Hello Mr. chandra,

If you convert the 21 digit octal (the maximum)

which is that maximum value also please tell the maximum for hex(16 digits)

Regards
Hardik

Chandra Bhatt
Ranch Hand
Posts: 1710
• Number of slices to send:
Optional 'thank-you' note:
Please see my previous post, which I have edited!
Actually I was calculating that for you!

In case of hexadecimal 16 digits are excluding 0x or 0X (in this case Java is not case sensitive "0x" and "0X" keep same meaning).

We are talking about maximum range, and you know long is there to hold them ofcourse.

You calculate yourself what maximum octal and hexadecimal values int can hold.

Did you get it well?

Thanks and Regards,
cmbhatt
[ April 07, 2007: Message edited by: Chandra Bhatt ]

Hardik Raja
Ranch Hand
Posts: 117
• Number of slices to send:
Optional 'thank-you' note:
ya i got a bit of it...but still confused

but then why is this giving complilation error( integer number too large )

long b = 0777777777777777777777;

long a = 0x7FFFFFFFFFFFFFFF;

Chandra Bhatt
Ranch Hand
Posts: 1710
• Number of slices to send:
Optional 'thank-you' note:

ya i got a bit of it...but still confused

but then why is this giving complilation error( integer number too large )

long b = 0777777777777777777777;

long a = 0x7FFFFFFFFFFFFFFF;

Hey Raja,
Try this and think, about the bold line I write after these two lines...

Think, what is by default int?

Now is that clear?

Regards,
cmbhatt

Hardik Raja
Ranch Hand
Posts: 117
• Number of slices to send:
Optional 'thank-you' note:
oh Thank you Sir...

Well now its clear...as by default it goes in an int

 Seriously? That's what you're going with? I prefer this tiny ad: the value of filler advertising in 2021 https://coderanch.com/t/730886/filler-advertising