answersLogoWhite

0


Best Answer

#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
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

#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();

}

This answer is:
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.

Related questions

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


How do you convert binary number to bcd number on paper?

Example Binary 00111000 Convert to Decimal 56 Convert to BCD by using groups of four binary numbers for each digit 5 6 0101 0110


How do you convert octal to binary with 2 decimal nos?

The conversion of octal number to binary can be obtained by using two methods. First, it can be converted into decimal and then obtained decimal is converted into binary. In the second method


Convert decimal number to binary number using stack?

becomes heavy because the ang decimal number ay marami kay sa sa stack ng tsinelas


What does binary number 1111000 convert to in decimal numbers?

111100002 equals 24010 using unsigned notation. It equals -1610 using signed notation.


Convert each decimal fraction to binary using repeated-multiplication-by-2?

0.9028


What is the binary equivalent of the decimal number 368?

The binary equivalent is 101110000. If you're using Windows 7, the built-in calculator will convert numbers between base 10, 8, 2 &amp; hex


Which binary number corrresponds to 00000111 decimal?

IF you are asking what that binary number is in decimal form... it would be 7. The question though seems to be asking waht that decimal number is in binary. You want to know what 111 is in binary? 1101111. Try using google. "111 in binary" as a search phrase gives you the answer.


C plus plus program that convert decimal to binary using the concept of stack?

#include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; main() { int number,binary[10000],b=0; printf("Enter decimal number "); scanf("%d",&amp;number); printf("\nBinary: "); for(;number;number/=2,b++) binary[b]=number%2; for(b--;b&gt;-1;b--) printf("%d ",binary[b]); }


Convert the decimal fraction of 0.32 to binary using the sum of weight method?

This is actually a question in my Digital Circuits text. Are they kidding? Is there a way to tell that a discrete decimal will have an endless binary equivalent?


What is the binary equivalent of the decimal number 23?

To convert decimal to binary, divide the decimal number you want to convert by 2 and write down the remainder. Repeat this until the final result is zero. The remainders you wrote down, written from the last one you wrote to the first (so the opposite order from which you derived them) is the binary equivalent.So using this method with the number 23 we get:23/2 = 11 remainder 111/2 = 5 remainder 15/2 = 2 remainder 12/2 = 1 remainder 01/2 = 0 remainder 1So the binary equivalent is 10111


How do you generate BCD output?

BCD (Binary Coded Decimal) output can be generated using decimal-to-BCD conversion algorithms. One common method involves dividing the decimal number by 10 and storing the remainder as the Binary Coded Decimal digit. This process is repeated until all decimal digits are converted into BCD form. Alternatively, some microcontrollers have built-in instructions to directly convert decimal numbers to BCD format.