
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C Program for Decimal to Binary Conversion?
Convert an integer from decimal number system (base-10) to binary number system (base-2). Size of an integer is assumed to be 32 bits, need you to divide the number by the base. It is used by the computer to change integer values to bytes that are a computer.
Input:10 Output:1010
Explanation
If the Decimal number is 10
When 10 is divided by 2 remainders is zero. Therefore, 0.
Divide 10 by 2. New number is 10/2 = 5.
when 5 is divided by 2 Remainder is 1. Therefore 1.
Divide 5 by 2. New number is 5/2 = 2.
when 2 is divided by 2 Remainder is zero. Therefore, 0.
Divide 2 by 2. New number is 2/2 = 1.
when 1 is divided by 2 Remainder is 1. Therefore, 1.
Divide 1 by 2. New number is 1/2 = 0.
number becomes = 0. Print the array in reverse order. The equivalent binary number is 1010.
Example
#include <iostream> using namespace std; int main() { long n, d, r, binary = 0; n=10; d = n; int temp = 1; while (n!=0) { r = n%2; n = n / 2; binary = binary + r*temp; temp = temp * 10; } printf("%ld", binary); return 0; }
- Related Articles
- Program for Binary To Decimal Conversion in C++
- Program for Decimal to Binary Conversion in C++
- Decimal to Binary conversion using C Programming
- Program for decimal to hexadecimal conversion in C++
- Program for octal to decimal conversion in C++
- Decimal to Binary conversion\n
- Recursive Program for Binary to Decimal in C++
- Decimal to binary list conversion in Python
- Decimal to binary conversion using recursion in JavaScript
- C# Program to Convert Binary to Decimal
- C++ Program To Convert Decimal Number to Binary
- C# Program to Convert Decimal to Binary\n
- C program to convert decimal fraction to binary fraction
- Binary Tree to Binary Search Tree Conversion in C++
- C++ program for hexadecimal to decimal

Advertisements