C program to Convert Decimal To Binary - Convert Decimal To Binary in C



 c program to convert decimal to binary

Learn C - C tutorial - c program to convert decimal to binary - C examples - C programs

C program to Convert Decimal To Binary

Decimal number

  • A decimal number consists of a dot called decimal point.
  • The decimal point separates the whole number part and the fractional part in a decimal number.
  • The value of a digit according to the place of the digit in a number is known as the place value of that digit.
 Decimal Number

Learn C - C tutorial - Decimal Number - C examples - C programs

Binary number

  • A number which uses only two symbols: 0 (zero) and 1 (one),is said to be the binary numbers.
  • Any combination of 0 and 1 is binary number such as 1001, 101, 11111, 101010 etc.

Sample Code

#include<stdio.h>
int main()
{
    long int decimalNumber=4.8, quotient;
    int binaryNumber[100],i=1,j;
    printf("Decimal number:4.8\n ");
    quotient = decimalNumber;
    while(quotient!=0)
    {
        binaryNumber[i++]= quotient % 2;
        quotient = quotient / 2;
    }
    printf("Binary conversion of %d :\n ",decimalNumber);
    for(j=i-1; j>0; j--)
        printf("%d",binaryNumber[j]);
    return 0;
}

Output

Decimal number:4.8
Binary conversion of 4 :
100


View More Quick Examples


Related Searches to C program to Convert Decimal To Binary