In this video we will see Decimal to Binary conversion using C++. Here C++ program take a decimal number as input, and convert the given decimal number into an equivalent binary number. For converting Decimal numbers into binary numbers, use different methods such as formula, division method, and so on.
Here, use the remainder formula. Steps to convert decimal number to binary number using decimal to the binary formula are as follow,
Step 1: Divide the given decimal number by 2, find the remainder (Ai).
Step 2: Now divide the quotient (Bi) that is obtained in the above step by 2, find the remainder.
Step 3: Repeat the above steps 1 and 2, until 0 is obtained as a quotient.
Step 4: Write down the remainder in the following manner: the last remainder is written first, followed by the rest in the reverse order (An, A(n – 1) …. A1). thus binary conversion of the given decimal number will be obtained.
Examples for Decimal to binary in C++:
Input : 7
Output : 111
Input : 10
Output : 1010
Input: 33
Output: 100001
C++ Program on Decimal to Binary Conversion: https://www.geeksforgeeks.org/program-decimal-binary-conversion/