class q1{
public static void main(String []s){
q2 q = new q2();
q.convert(9); //any input
q.display();
}
}
class q2{
int bin[] = new int[8]; //output has been considered as 8 bit
int i=7;
void convert(int k){
int t=k;
while(t>0){
int r=t%2;
t/=2;
bin[i--]=r;
}
}
void display(){
int j=0;
while(j!=8){
System.out.print(bin[j++]);
}
System.out.println();
}
}
/*
OUTPUT
00001001
*/
No comments:
Post a Comment