• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Binary literal problem

 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


F:\Binary Literal>javac BinaryLiterals.java
BinaryLiterals.java:3: error: ')' expected
System.out.println(0b10101010101010101010101010101011d);
^
BinaryLiterals.java:3: error: illegal start of expression
System.out.println(0b10101010101010101010101010101011d);
^
2 errors
 
Paul Clapham
Sheriff
Posts: 21116
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since binary literals are a new feature in Java 7, can you confirm that you tried to compile that code with a Java 7 compiler?
 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Since binary literals are a new feature in Java 7, can you confirm that you tried to compile that code with a Java 7 compiler?


Yes,I on 7.With letter L code is working but why not with d letter.And if i delete d letter then it will compile fine.But as i know ,d is for integer, we write or not it shouldn't effect compilation then why it is giving compile error if i use d letter. thanks
 
Matthew Brown
Bartender
Posts: 4567
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saloni jhanwar wrote:But as i know ,d is for integer

What makes you think that? d indicates a double, i.e. not an integer literal, so you can't mix it with an integer-specific literal form. Are you getting confused with format strings?
 
Paul Clapham
Sheriff
Posts: 21116
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oracle's page describing binary literals starts out by saying this:

Oracle wrote:In Java SE 7, the integral types (byte, short, int, and long) can also be expressed using the binary number system.
 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Matthew Brown & Paul Clapham.I got confused because of my mindset d for integer
 
BalaMurali dhar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code
public class BinaryLiterals {
public static void main(String args[]){
System.out.println("0b10101010101010101010101010101011d");
System.out.println("0b10101010101010101010101010101011L");
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic