Skip to main content

Help with binary numbers

Please note these forums are being decommissioned and use the new and improved forums at
2 replies [Last post]
Joined: 2011-04-06

I get a compiler error on the following expression. The Java tutorials shows the expression as valid in the Primitive Data Types section:
int x = 0b11010; // binary notation

The compiler gives me the following error message: ';' expected
int x = 0b11010;
1 error
Is the notation not allowed?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2011-05-05

The above number 0b11010 is Octal format and so compiler is giving the error when you executing the expression. So you need to replace b with x n and make this number hexedecimal 0xb11010 so that compiler recognises it and compile without any errors.
Here is program:

public class TestClass

public static void main(String[] args)

int x = 0xb11010;
System.out.print("binay no.." + x);


so when u execute this program it will shows the below output:
binay no..11603984
so make this no hexadecimal and compile will compile without any error.
Amit Soni

Joined: 2011-04-06

Wait, is the compiler saying that he expected the ';' in the line of 'int x = 0b11010;'?
Most times that mean, the line abouve has no ';'. The compiler just want to say that from the end of the last line to the beginning of the next line (in your case 7), he is missing a ';'.