Converting Decimal to Binary using C Program with Source Code

Introduction

The C programming language is a procedural programming language. Between 1969 and 1973, Dennis Ritchie worked on the project. It was created primarily as a system programming language for developing operating systems. Low-level memory access, a small collection of keywords, and a clean style are all qualities that make C language excellent for system programming, such as operating system or compiler development.

Why Learn C Programming Language?

Because it mixes the characteristics of high-level languages with the functionalism of assembly language, C is often referred to as a middle-level computer language. The manipulation of bits, bytes, and addresses in C gives the programmer more control over how the program will behave and more direct access to the underlying hardware mechanisms.

Working programmers influenced, influenced, and field-tested C. As a result, C provides the programmer with exactly what he or she want. C++ is a more advanced version of the C programming language. C++ incorporates all of the features of C, as well as support for object-oriented programming (OOP). Furthermore, C++ includes numerous enhancements and features that make it a “better C,” regardless of whether or not it is used for object-oriented programming.

Decimal and Binary Number Systems

Decimal Number Systems

The decimal number system employs ten symbols to represent numbers with a base of ten: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. It’s also known as the Hindu-Arabic number system, in which each digit has a location and is ten times more important than the one before it. A decimal point is also used to denote decimal fractions.

Binary Number Systems

The binary number system is a base-2 number system in which numbers are only represented by two digits: 0 and 1. A bit is the abbreviated form of ‘binary digit,’ which is the smallest unit of data in a computer. A bit has only one binary value: either 1 or 0.

Decimal to Binary Table

Decimal NumbersBinary Numbers
00
11
210
311
4100
5101
6110
7111
81000
91001
101010
111011
121100
131101
141110
151111
1610000
1710001
1810010
1910011
2010100

Converting Decimal to Binary

To convert numbers from decimal to binary, divide the given decimal value by 2 and record the remainders until the final quotient is zero. Then the remainders are traced from the bottom to the top and hence we get the binary number of the respective decimal number.

Example: Convert (160)10 to (?)2

DividerDividendRemainder
21600
2800
2400
2200
2100
251
220
21

From above definition and table we get :

(160)10 = (10100000)2

Converting Decimal to Binary using C Program

The best way to learn is to do. Hence, what better way to learn C programming language (if you know the basics) than to code your first mini project. In this tutorial we are going to build a program for converting a decimal number to binary number using c programming language. Keep in mind this is a mini project for absolute beginners and intermediate programmers as well.

// C program to convert decimal number to binary number 

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
 
int main()
{
int number,cnt,i;
int bin[32];
printf("Enter the Decimal number: ");
scanf("%d",&number);
// initialize index to zero
cnt=0;              
while(number>0)
{
bin[cnt]=number%2;
number=number/2;
cnt++;
}

// print value in reverse order
printf("The converted Binary number is: ");
for(i=(cnt-1); i>=0;i--)
printf("%d",bin[i]);
return 0;
}

Output

  • Output Screen Shot 1 :

  • Output Screen Shot 2 :
  • Output Screen Shot 3 :
  • SHARE Converting Decimal to Binary using C Program with Source Code

    You may also like...

    Leave a Reply

    Your email address will not be published.

    Share