answersLogoWhite

0

#include #include
void main()
{
int a[20],b,c,d,i=0;
printf("Enter a decimal no. to convert it into binary no.");
scanf("%d",&b);
c=b;
while(b>0)
{
d[i]=b%2;
i++;
b=b/2;
}
i--;
printf("\nBinary equivalent of decimal no. %d is ",c);
while(i>=0)
{
printf("%d",d[i]);
i--;
}
getch();
}

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

BeauBeau
You're doing better than you think!
Chat with Beau
ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
ReneRene
Change my mind. I dare you.
Chat with Rene
More answers

In words:- All binary numbers can be found from base 10 by inserting 1 for any power of 2 and zero for any powers of two that are absent.

For example:- write down the series of 2 to power n to help:-

1,2,4,8,16,32,64,128,256.........

so to find 93 we have 64 + 0x32 + 16 +8 +4 + 0x2 +1 giving 1011101

I would have to give this a bit more thought as to how to set this out as a mathematical instruction but it is easy to see the logic from the above.

User Avatar

Wiki User

16y ago
User Avatar

Repetitively divide by 2, then take the remainder (either a 0 or 1) as the digit. Example:

19 (base 10).

  • 19/2 = 9 remainder 1 (this is the least significant digit)
  • then 9/2 = 4 remainder 1.
  • 4/2 = 2 remainder 0.
  • 2/2 = 1 remainder 0.
  • 1/2 = 0 remainder 1.

So 10011 is equivalent to 19. Check arithmetic: 10011 --> 16 + 2 + 1 = 19. Try one more 25:

  • 25/2 = 12 remainder 1.
  • 12/2 = 6 remainder 0.
  • 6/2 = 3 remainder 0.
  • 3/2 = 1 remainder 1.
  • 1/2 = 0 remainder 1.

So 11001 base 2 is 25 base 10. Check: 11001 --> 16 + 8 + 1 = 25.

User Avatar

Wiki User

13y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Decimal numbers into their equivalent binary numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp