Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java2 Sun Certified Programmer & Developer by Sierra and Bates  RSS feed

 
Zee Morris
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

Java2 Sun Certified Programmer & Developer by Sierra and Bates (chpt1 p.13).
Describes an octal number can hold 21 digits (not including the leading zero).
And 16 for a hexdecimal number (not including the prefix 0x).

However my attempt at this in practice produced the following compilation error for an Octal literal:

public class IntlitOctalTest {
public static void main(String [] args){
int b = 0111111111111111111111; // IntLitTest.java:7: integer number too large

System.out.println("Octal Numbers: " + b);


And the following for a Hex:

public class IntlitTest {
public static void main(String [] args){

int b = 0x0123456789ABCDeF; //IntLitTest.java:7: integer number too large

System.out.println("Hex Numbers: " + b);

}
}

In light of this can someone explain what is meant by an octal literal having the ability to hold 21 digits, and 16 for a Hexdecimals?

Thank you,
Zee
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very long octal or hexidecimal constants, just like long decimal constants, won't fit in a 32-bit "int"; they can be held in a 64-bit "long", however. You have to append the letter "L" to the constant to make it a long value.

Try

long octal = 0123456789123456789123L;
[ May 07, 2007: Message edited by: Ernest Friedman-Hill ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[EFH]: Try

long octal = 0123456789123456789123L;


Ummmm... you sure about that?
 
Vaibhav Wahee
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To simple test to clear that out.....
open up the calculator in windows and do the following
2(x^y)63 and then subtract 1 from the value and then select the Oct radio button and u'll get the answer as 777777777777777777777
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!