#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();
}
Chat with our AI personalities
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.
Repetitively divide by 2, then take the remainder (either a 0 or 1) as the digit. Example:
19 (base 10).
So 10011 is equivalent to 19. Check arithmetic: 10011 --> 16 + 2 + 1 = 19. Try one more 25:
So 11001 base 2 is 25 base 10. Check: 11001 --> 16 + 8 + 1 = 25.
8 in decimal is 1000 in binary
The number 6 in binary is 110
3310 = 1000012
It is a decade counter with a binary to decimal translator meaning it can take binary and turn it into decimal numbers for example a seven segment display
Write algorithms and draw a corresponding flow chart to convert a decimal number to binary equivalent?