- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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

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.

#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 Questions & Answers
- Program for Binary To Decimal Conversion in C++
- Program for Decimal to Binary Conversion in C++
- Decimal to Binary conversion
- Program for decimal to hexadecimal conversion in C++
- Program for octal to decimal conversion in C++
- Decimal to Binary conversion using C Programming
- Decimal to binary list conversion in Python
- Recursive Program for Binary to Decimal in C++
- Decimal to binary conversion using recursion in JavaScript
- C# Program to Convert Binary to Decimal
- C# Program to Convert Decimal to Binary
- C++ Program To Convert Decimal Number to Binary
- C++ program for hexadecimal to decimal
- Binary to decimal using C#
- C program to convert decimal fraction to binary fraction

Advertisements