Decimal to equivalent Binary coderinme

Decimal to equivalent Binary coderinme

Decimal to equivalent Binary coderinme
To convert any given decimal number into it’s equivalent binary form, we use the factorization method. I just hope you remember the factorization method that we learned in our school days. Beginning with the process, at each step, we check the divisibility of the given decimal number by two (2) and keep on noting the remainder at every single step sideways. Finally, to get the equivalent binary form, we assemble all the remainders noted noted earlier, by writing the remainders in the reverse order. One thing in this program we we can cross check our answer. For this we start from the extreme right, in the increasing order of power of two (2).

Let’s write a program in C which converts the given decimal number into its equivalent binary form. It’s really very simple. No worries. Check it out.

#include<stdio.h>
int main()
{
int a[20], dec, i=0,j;
printf("\nEnter the decimal number: ");
scanf("%d",&dec);
j = dec;
while( dec > 0 )
{
a[i]=dec%2;
i++;
dec=dec/2;
}
printf("\nEntered Decimal No : %d\nConverted Binary number is : ",j);
for(j=i-1;j>=0;j--)
{
printf("%d",a[j]);
}
getch();
return 0;
}

For more programs in C, visit our C Coder Archives

Decimal to equivalent Binary coderinme

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.