May 18, 2017

Srikaanth Kumar

How to Check The Given Number Is Binary Number or Not Java Program


Write a program to check the given number is binary number or not?

The binary numeral system, or base-2 number system, represents numeric values using two symbols: 0 and 1. More specifically, the usual base-2 system is a positional notation with a radix of 2. Because of its straightforward implementation in digital electronic circuitry using logic gates, the binary system is used internally by almost all modern computers.


package com.java2novice.algos;

public class MyBinaryCheck {

    public boolean isBinaryNumber(int binary){
        boolean status = true;
            if(binary == 0){
            } else {
                int tmp = binary%10;
                if(tmp > 1){
                    status = false;
                binary = binary/10;
        return status;
    public static void main(String a[]){
        MyBinaryCheck mbc = new MyBinaryCheck();
        System.out.println("Is 1000111 binary? :"+mbc.isBinaryNumber(1000111));
        System.out.println("Is 10300111 binary? :"+mbc.isBinaryNumber(10300111));


Is 1000111 binary? :true
Is 10300111 binary? :false

Subscribe to get more Posts :