TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C Program to convert Decimal to Binary

C Program to convert Decimal to Binary in C with programming examples for beginners and professionals covering concepts, control statements, c array, c pointers, c structures, c union, c strings and more.

<< Back to C

C Program to convert Decimal to Binary

Decimal to binary in C: We can convert any decimal number (base-10 (0 to 9)) into binary number(base-2 (0 or 1)) by c program.

Decimal Number

Decimal number is a base 10 number because it ranges from 0 to 9, there are total 10 digits between 0 to 9. Any combination of digits is decimal number such as 23, 445, 132, 0, 2 etc.

Binary Number

Binary number is a base 2 number because it is either 0 or 1. Any combination of 0 and 1 is binary number such as 1001, 101, 11111, 101010 etc.

Let's see the some binary numbers for the decimal number.

DecimalBinary
11
210
311
4100
5101
6110
7111
81000
91001
101010

Decimal to Binary Conversion Algorithm

  • Step 1: Divide the number by 2 through % (modulus operator) and store the remainder in array
  • Step 2: Divide the number by 2 through / (division operator)
  • Step 3: Repeat the step 2 until number is greater than 0

Let's see the c example to convert decimal to binary.

#include  
#include
int main(){
int a[10],n,i;  
system ("cls");
printf("Enter the number to convert: ");  
scanf("%d",&n);  
for(i=0;n>0;i++)  
{  
a[i]=n%2;  
n=n/2;  
}  
printf("\nBinary of Given Number is=");  
for(i=i-1;i>=0;i--)  
{  
printf("%d",a[i]);  
}  
return 0;
}

Output:

Enter the number to convert: 5
Binary of Given Number is=101 



Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf