java 7 binary literals example

Binary Literals

In Java 7, the integral types (byte, short, int, and long) can also be expressed using the binary number system. To specify a binary literal, add the prefix 0b or 0B to the number.

Java binary literals example

package com.w3spoint;
 
public class Java7BinaryLiterals {
	public static void main(String args[]){
		int i=0b01111;
		byte b=(byte) 0b01111;
		long l=(long) 0B01111L;
		System.out.println("i="+i);
		System.out.println("b="+b);
		System.out.println("l="+l);
	}
}




Output

i=15
b=15
l=15
Content Protection by DMCA.com
Please Share