answersLogoWhite

0

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

15y ago

What else can I help you with?