# C++ program to convert binary number to decimal and vice-versa

The binary numeral system uses the number 2 as its base (radix). As a base-2 numeral system, it consists of only two numbers: 0 and 1.
The decimal numeral system is the most commonly used and the standard system in daily life. It uses the number 10 as its base (radix). Therefore, it has 10 symbols: The numbers from 0 to 9; namely 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.

#### How to Convert Binary to Decimal

Step 1: Write down the binary number.

Step 2: Starting with the least significant digit (LSB - the rightmost one), multiply the digit by the value of the position. Continue doing this until you reach the most significant digit (MSB - the leftmost one).

Step 3: Add the results and you will get the decimal equivalent of the given binary number.

#### Example: (1010)2

Step 1: Write down (1010)2 and determine the positions, namely the powers of 2 that the digit belongs to.
Step 2: Represent the number in terms of its positions. (1 * 23) + (0 * 22) + (1 * 21) + (0 * 20)
Step 3: (1 * 8) + (0 * 4) + (1 * 2) + (0 * 1) = 8 + 0 + 2 + 0 = 10
Therefore, (1010)2 = (10)10

### C++ program to convert binary number to decimal

#### Output

Enter a binary number: 1101
1101 in binary = 13 in decimal

### C++ Program to convert decimal number to binary

#### Output

Enter a decimal number: 13
13 in decimal = 1101 in binary