Binary To Decimal In C
The idea involved in the programming of “Binary To Decimal Conversion In C” is to extract the digits of a given binary number starting from the rightmost digit and keep a variable dec_value. At the time of extracting digits from the binary number, multiply the digit with the proper base (Power of 2) and add it to the variable dec_value. In the end, the variable dec_value will store the required decimal number.
For Example:
If the binary number is 101.
dec_value = 1*(2^2) + 0*(2^1) + 1*(2^0) = 5
This program takes a binary number as input and converts it into a decimal number. Take a binary number as input. Multiply each digit of the binary number starting from the last with the powers of 2 respectively. Add all the multiplied digits. The total sum gives the decimal number.
Binary To Decimal In C
Output:
Explanation Of Code:
- Take a binary number and store it in the variable num.
- Initialize the variable decimal_val to zero and variable base to 1.
- Obtain the remainder and quotient of the binary number. Store the remainder in the variable rem and override the variable num with quotient.
- Multiply rem with variable base. Increment the variable decimal_val with this new value.
- Increment the variable base by 2.
- Repeat steps 3, 4 and 5 with the quotient obtained until the quotient becomes zero.
- Print the variable decimal_val as output.
Top Book Suggestion
The two books on C Programming Language that I Personally Recommend. I really loved reading these books. These books are listed for quality content, easy steps, and affordable price. You can get it from Amazon and Flipkart.
Check The Price On Amazon:
Check The Price On Flipkart:
Buy Premium Courses At Lowest Price. Become A Certified Developer Today!
Important C Programs
Basic C Programs
Programs On Number
String Programs
Array Programs
Sorting Programs
Pointer Programs
Star Pattern Programs
Number Pattern Programs
File Handling Programs
Programs On Recursion
Geometry Programs
Programs On Loop
Programs On Function
Switch Case Programs
If Else Programs
Bitwise Operator
Conditional Operator
Matrix Programs
Program On Calculation
Number System Conversion
All C programs