answersLogoWhite

0

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

{

long int a[20],i,n,count=0,b[20],c[20],sum=0;

printf("ENter the number in binary form=\t");

scanf("%ld",&n); // Get a binary number from the user

for (i=0;n>=1;i++)

{

a[i]=n%10;

n=n/10; // Loop To reverse the number And put all reversed numbers in arry a[i]

count=count + 1; // count to count the number of times this loop runs

}

for (i=0;i<=count-1;i++) // count -1 condition is used to run the loop till the previous loop run

{

b[i]=pow(2,i); // This is to raise the power of 2 to no of times previous loop runned.

}

for (i=0;i<=count-1;i++)

{

c[i]=a[i] * b[i]; // Multiply a[i] or reveresed binary no with b[i] or increasing pow of 2 to count-1

sum=sum +c[i]; // it is to add the c[i] elements with each other n put into sum variable.

}

printf("Decimal form =%ld",sum); // printing the sum to get the decimal form

getch();

}

// Hope it solves your problem, ANy more assistance honey.gupta13@Yahoo.com ffffff

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra
More answers

#include<stdio.h>

#include<conio.h>

void main()

{

char base16[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

long num;

long cnum[68];

int base,number,i,j;

clrscr();

printf("\nEnter a decimal number to convert : ");

scanf("%ld",&num);

printf("\nEnter base for convert : 2(for binary),8(for octal),16(for hexadecimal) : ");

scanf("%d",&base);

i=0;

while(num!=0)

{

cnum[i]=num%base;

num=num/base;

i++;

}

i=i--;

printf("\nThe number in your base is : ");

for(i=i;i>=0;i--)

{

number=cnum[i];

printf("%c",base16[number]);

}

getch();

}

User Avatar

Wiki User

14y ago
User Avatar

Add your answer:

Earn +20 pts
Q: How do you convert decimal number to binary number using while loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


Write a Program to convert decimal number into hexadecimal no without using function and string?

This is not a question.


Write a C program to add an integer and a decimal number?

include &lt;iostream&gt; using namespace std; int main() { int n; // number to convert to binary while (cin &gt;&gt; n) { if (n &gt; 0) { cout &lt;&lt; n &lt;&lt; " (decimal) = "; while (n &gt; 0) { cout &lt;&lt; n%2; n = n/2; } cout &lt;&lt; " (binary) in reverse order" &lt;&lt; endl; } else { cout &lt;&lt; "Please enter a number greater than zero." &lt;&lt; endl; } } return 0; }//end main


Program to convert binary to decimal without using array?

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 iDoing 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;


Conversion of binary to octal?

Binary is a base 2 number system, while octal is base 8. This happens to make conversion between binary and octal fairly trivial, although more complex than conversion to hexadecimal. To convert to octal from binary, take each three bits, starting from the least significant bit, and convert them to their octal equivalent. Examples: 25510 = 111111112 = 11 111 111 = 3778 17410 = 101011102 = 10 101 110 = 2568 You can repeat this process for as many bits as you need. A 24-bit number should translate into 8 octal numbers, for reference.