![]() |
VOOZH | about |
In this article, we will learn how to write a C program to convert the given binary number into an equivalent decimal number. Binary numbers are expressed in base 2 ( 0, 1 ) and decimal numbers are expressed in base 10 ( 0-9 ).
The below diagram explains how to convert ( 1010 ) to an equivalent decimal value:
👁 binary to decimal in c169
Time complexity: O(d), where d is the number of digits in binary number.
Auxiliary Space: O(1)
In the above program, we represented a binary number as integer value with base 10 as binary numbers are not directly supported by C language. One more common representation of binary number is in the form of strings. If the binary number is in the form of string, then the above program can be modified as shown:
169
Time complexity: O(d), where d is the number of digits in binary number.
Auxiliary Space: O(1)
Refer to the complete article Program for Binary To Decimal Conversion for more details!