This is a Java Program to Illustrate Use of Binary Literals.A literal is an explicit value. To specify a binary literal, add the prefix 0b or 0B to the number. For example : int number=123;
The value 123 is a literal. Since it’s a normal base-10 value, we might say it is a decimal literal.
We use binary literals with different type of datatypes like byte, short and int to illustrate its use. We also use addition operation to add two binary literals.
Here is the source code of the Java Program to Illustrate Use of Binary Literals. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Binary_Literal
public static void main(String args)
byte aB = 0b00100001;
short aS = 0b10100010100;
int a1 = 0b10110;
int a2 = 0b101;
int a3 = 0b1011;
$ javac Binary_Literal.java
$ java Binary_Literal
Sanfoundry Global Education & Learning Series – 1000 Java Programs.
Here’s the list of Best Reference Books in Java Programming, Data Structures and Algorithms.
Participate in the Sanfoundry Certification contest
to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!
, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @