Free Tutorials, Linux Command, Source Code Architecture,  Software Engineering, Intelligent Systems, RDBMS, Computer Accounting,  Operations Research, Discrete Mathematics, Network, SAD Lay Networks Lay Networks
Computer Science Networking Operating Systems Linux and Unix Source Code Script & Languages Protocols Glossary
 


/* Write an algorithim/progroam to convert a number into binary */ (contributed by*: Subramani)


#include<stdio.h>

main()
{
int num,no_bits;
clrscr();
printf("enter a number");
scanf("%d",&num);
no_bits=count_bits(num);
printf("number of bits %d\t",no_bits);
bin_print(num,no_bits);
}
count_bits(int n) /* function to count number of bits */
{
int i=0;
for (;n!=0;n=n>>1)
i++;
return(i);
}
bin_print(int x, int n_bits)
/* function to print decimal numbers in binary format */
{
int j;
printf("no. %d in binary \t",x);
for(j=n_bits-1; j>=0;j--)
printf("%i",(x>>j) & 01);
}

Decimal To Binary algorithm (contributed by*: Rimincha Ammu)

------------------------------------------------------

start
1.let num be an array of integer
2.input no.
3.let rem=0,ctr=0
4.while(rem!=1)
begin
q=no/2
rem=no mod 2
num[ctr]=rem
ctr++
no=q
end
5.while(ctr>=0)
begin
print num[ctr]
ctr=ctr-1
end
end
------------------------------------------------------------
Shell Program

clear
echo "Enter your number"
read num
x=`expr $num`
echo " " > db.txt
i=0
while [ $num != 0 ]
do
rem=`expr $num % 2`
echo -n $rem >> db.txt
n1=`expr $num / 2`
num=`expr $n1`
i=`expr $i + 1`
done
echo -n binary of $x is:
j=`expr $i`
while [ $j != 0 ]
do
w=`cut -c $j db.txt`
j=`expr $j - 1`
echo -n $w
done
echo
echo

Top

Back
free computer articles
 

Copyright © 2000- 2008 Lay Networks All rights reserved. 

Web Hosting sponsored by Customized Software Company India
Web Site Designed by Web Designing, Flash Animation, Multimedia Presentations, Broacher/catalogue designing, Web Promotion 
Refer to your freind About Us Legal IGNOU Contact Us Feedback Donate to laynetworks.com Download Management Tutorials Tutorials History Search here