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

Still curious? Ask our experts.

Chat with our AI personalities

SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra

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