# how to do octal number comparision

swatione chowdary

Greenhorn

Posts: 27

posted 8 years ago

- 0

in this following code:

String number= "2042775656";

int num=Integer.parseInt(number);

System.out.println(num);

if(num >= 0000008704 && num <= 0000008999 ){

//some code....

}

it is giving the folloing error:

Octal 0000008704 (digit 8) is out of range .

then how can i compare

int num variable weather it falls between these numbers

0000008704 � 0000008999

String number= "2042775656";

int num=Integer.parseInt(number);

System.out.println(num);

if(num >= 0000008704 && num <= 0000008999 ){

//some code....

}

it is giving the folloing error:

Octal 0000008704 (digit 8) is out of range .

then how can i compare

int num variable weather it falls between these numbers

0000008704 � 0000008999

posted 8 years ago

- 0

You want to compare octal numbers ? But the octal system contains digits from 0 to 7. So 0000008704 is not an octal number.

[My Blog]
*All roads lead to JavaRanch*

posted 8 years ago

- 0

In Java (just like in C and C++), if you start an integer literal with a 0 (like you are doing with 0000008704 and 0000008999 in your code), it is interpreted as a number in the octal numeral system instead of as a decimal number.

You didn't mean to use octal numbers, so you should just remove the zeroes.

You didn't mean to use octal numbers, so you should just remove the zeroes.

swatione chowdary

Greenhorn

Posts: 27

posted 8 years ago

- 0

Sorry to repeat myself.

Neither 8704 nor 8999 are octal numbers.

Neither 8704 nor 8999 are octal numbers.

[My Blog]
*All roads lead to JavaRanch*

posted 8 years ago

- 0

Jesper is right... why do you need all those leading 0's? or why don't you use 0000000000000000000000000000000000000000000000000000008704 and 0000000000000000000000000000000000000000000000000000008999?

because you don't need leading 0's. Therefore, when you put one on your number, Java assumes you are writing a number in base-8. The only allowed digits in base-8 are 0,1,2,3,4,5,6, and 7. You're numbers have the digit '8', so Java is confused, and refuses to compile your code.

because you don't need leading 0's. Therefore, when you put one on your number, Java assumes you are writing a number in base-8. The only allowed digits in base-8 are 0,1,2,3,4,5,6, and 7. You're numbers have the digit '8', so Java is confused, and refuses to compile your code.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

I agree. Here's the link: http://aspose.com/file-tools |