Write a program to Convert Binary Notation to dotted decimal Notation In java
import java.util.*;
class Test{
public
static void main(String[] args){
Scanner
scn = new Scanner(System.in);
System.out.println("Enter
32 bit binary Notation:");
String
bin = scn.next();
int
logic = 0;
String
res = "";
if(bin.length()
> 32){
System.out.println("Invalid
Notation");
logic
= 1;
}
if(logic==0){
for(int
i=0;i<=24;i=i+8){
int
decimal=Integer.parseInt(bin.substring(i,i+8),2);
res
= res + String.valueOf(decimal)+".";
}
System.out.println("Dotted
Decimal Notation : "+res.substring(0,res.length()-1));
}
}
}
Comments
Post a Comment