Monday, August 9, 2010

Article | Program To Convert Binary Number to Hexadecimal Without using any functions/packages

Program To Convert Binary Number to Hexadecimal Without using any functions/packages..



import java.io.*;

class NewOne

{

public static void main(String args[])

{

System.out.print(" Enter a Binary Numbers : ");

int bin=0,d,a[]=new int[100],i=0,sum=0,hex,digit,s=1;



BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

try

{

bin=Integer.parseInt(br.readLine());

}catch(Exception e){}

char ch;

while(bin>0)

{

d=bin%10000;

while(d>0)

{

digit=d%10;

sum=sum+(digit*s);

s=s*2;

d=d/10;



}

a[i]=sum;

i++;

s=1;

sum=0;

bin=bin/10000;

}

for(i=i-1;i>=0;i--)

{

switch(a[i])

{

case 0:

case 1:

case 2:

case 3:

case 4:

case 5:

case 6:

case 7:

case 8:

case 9:

System.out.print(a[i]);

break;

case 10:

System.out.print("A");

break;

case 11:

System.out.print("B");

break;

case 12:

System.out.print("C");

break;

case 13:

System.out.print("D");

break;

case 14:

System.out.print("E");

break;

case 15:

System.out.print("F");

break;

}

}

}

}

Loading...

Comments :

0 comments to “ Program To Convert Binary Number to Hexadecimal Without using any functions/packages ”

Top Views

BloggerTipsTemplates

CHICKLETS

Enter your email address:

Delivered by FeedBurner

Followers