Conversion of Numbers in C

Google Advertisements

Prev Tutorial Next Tutorial

Number Conversion Program in C

With the help of C Language you can convert any number from decimal to binary and binary to decimal, binary to octal, binary to hexadecimal, decimal to octal and etc..

Decimal to Binary Conversion

Decimal number have base 10 and Binary number have base 2.

Decimal to Binary Conversion in C

#include<stdio.h>
#include<conio.h>

void main()
{
int no,rem[20],i=0,j;
clrscr();
printf("Enter any number: ");
scanf("%d",&no);
while(no>0)
{
rem[i]=no%2;
i++;
no=no/2;
}
printf("Binary number is: ");
for(j=i-1;j>=0;j--)
{
printf(" %d",rem[j]);
}
getch();
}

Output

Enter any number: 7
Binary number is: 111

Decimal to octal conversion

Decimal number have base 10 and Octal number have base 8.

Decimal to Octal Conversion Program in C

#include<stdio.h>
#include<conio.h>

void main()
{
int no,rem[20],i=0,j;
clrscr();
printf("Enter any number: ");
scanf("%d",&no);
while(no>0)
{
rem[i]=no%8;
i++;
no=no/8;
}
printf("Octal number is:");
for(j=i-1; j>=0; j--)
{
printf("  %d",rem[j]);
}
getch();
}

Output

Enter any number: 23
Octal number is: 2  7

Decimal to Hexadecimal Conversion

Decimal number have base 10 and Hexadecimal number have base 16.

Decimal to Hexa Conversion Program in C

#include<stdio.h>
#include<conio.h>

void main()
{
int num,rem[20],hex=0,i=0,j;
clrscr();
printf("Enter any number: ");
scanf("%d",&num);
while(num>0)
  {
    rem[i] = num % 16;
    num = num / 16;
    i++;
  }
printf("Hexadecimal number: ");
for(j=i-1; j>=0 ; j--)
  {
    switch(rem[j])
    {
      case 10:
	  printf("A");
	  break;
      case 11:
	  printf("B");
	  break;
      case 12:
	  printf("C");
	  break;
      case 13:
	  printf("D");
	  break;
      case 14:
	  printf("E");
	  break;
      case 15:
	  printf("F");
	  break;
      default :
	 printf("%d",rem[j]);
    }
  }
getch();
}

Output

Enter any number: 231
Hexadecimal number: E7

Prev Tutorial Next Tutorial

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. For Advertisement contact on hitesh.xc@gmail.com or 9999595223

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar. Difference between path and classpath in Java

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483 Try this Keyword C++ Programs