• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to display equivalent binary value in java 1.5  RSS feed

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While am trying to display a numerical digit from an equivalent binary value of integer data-type its working fine in JAVA 1.7 but not in JAVA 1.5
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sasikumar Senthilnathan wrote:While am trying to display a numerical digit from an equivalent binary value of integer data-type its working fine in JAVA 1.7 but not in JAVA 1.5

Sasikumar,

1. Welcome to javaRanch.
2. Could you show us your code? It's difficult to advise anything without that.

PS: I removed your second post, which looks like a duplicate to me.

Winston
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also, please show us what it DOES do. Does it compile in 1.5? Does it run? does it crash? does it give you an error message?

The more details you can give, the better your chances are someone can help you.
 
Sasikumar Senthilnathan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Winston Gutkowski and fred rosenberger

Here is my code:

The code works fine in JAVA 1.7 but not in JAVA 1.5?

It shows up the error


ValueAssignmentCheck.java:3: ';' expected
int binVal = 0b11010;
..................^..............................
1 error


I have used dots to notify where it is showing the error.

Thanks in Advance.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Binary literals were introduced in Java7. For Java5 you would have to write 0x1a or 26.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a look at the relevant part of the Java Tutorials. It shows decimal, hexadecimal and binary integer literals. It doesn't show octal literals, nor does it say that binary is only available in Java7, even though it says that _ characters are only permitted in Java7 literals.

Actually, I do not like octal numbers; as far as I am concerned octal is obsolete. But I think that tutorials section could do with a bit of improvement. This is the Java Language specification section about the same subject and this is the Java5 version.
Notice the strange feature that all integer literals are 0 or positive, but octal and hex (and I think binary) have double the range of decimal.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!