Forums Register Login

Binary literal problem

+Pie Number of slices to send: Send


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
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
 

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
1
+Pie Number of slices to send: Send
 

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?
1
+Pie Number of slices to send: Send
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.

 
+Pie Number of slices to send: Send
Thanks Matthew Brown & Paul Clapham.I got confused because of my mindset d for integer
+Pie Number of slices to send: Send
This is the code
public class BinaryLiterals {
public static void main(String args[]){
System.out.println("0b10101010101010101010101010101011d");
System.out.println("0b10101010101010101010101010101011L");
}
}
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1128 times.
Similar Threads
shifting
Compile time Difference between // and /* */
casting of double to float
Byte Literal
StringBuffer not work,help me.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:49:05.