Declaring Binary Literals - Java Language Basics

Java examples for Language Basics:Primitive Types

Introduction

Use binary literals to make your code readable.

Demo Code

public class Main {

    public static void main(String[] args) {
        int bin1 = 0b1100;
        short bin2 = 0B010101;
        short bin3 = (short) 0b1001100110011001;

        System.out.println(bin1);
        System.out.println(bin2);
        System.out.println(bin3);


    }/*from w  ww  .  j  a va  2 s.  c  om*/
}

Result


Related Tutorials