answersLogoWhite

0


Best Answer

Suppose your binary number is stored in a series of bits in the unsigned long type named bits.

Then the fragment of a C program to convert this number to a decimal value would be ..

double decimal_value = 0.0;

for ( unsigned long i = 0; i < sizeof(unsigned long); ++i)

{

decimal_value += pow(2,i) * ( bits & 1 );

bits >> 1; // shift all the bits to the right one spot.

} // end for i

Doing this work is generally unnecessary as functions such as these are built in to most programing languages.

Another method for this: double decimal_value= bits;

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Program to convert binary to decimal without using array?
Write your answer...
Submit
Still have questions?
magnify glass
imp