C Programming Code Examples C > For Loops and While Loops Code Examples Program to convert decimal to binary more than 18 bits Program to convert decimal to binary more than 18 bits Write a C program to input decimal number from user and convert to binary number system. How to convert from decimal number to binary number system in C program. Logic to convert decimal to binary number system in C programming. Decimal number system is a base 10 number system. Decimal number system uses only 10 symbols to represent all number i.e. 0123456789 Binary number system is a base 2 number system. Binary number system uses only 2 symbols to represent all numbers i.e. 0 and 1 /* C program to convert from Decimal to Binary number system */ #include <stdio.h> #include <string.h> int main() { long decimal, tempDecimal; char binary[65]; int index = 0; /* Input decimal number from user */ printf("Enter any decimal value : "); scanf("%ld", &decimal); /* Copy decimal value to temp variable */ tempDecimal = decimal; while(tempDecimal > 0) { binary[index] = (tempDecimal % 2) + '0'; tempDecimal /= 2; index++; } binary[index] = '\0'; /* Reverse the converted binary to get final binary result */ strrev(binary); printf("Decimal value = %ld\n", decimal); printf("Binary value of decimal = %s", binary); return 0; }