Laynetworks  
Web laynetworks.com Google
Home | Site Map | Tell a friends
Journal of Management
Management Tutorials
Download
Tutorials
History
Computer Science
Networking
OS - Linux and Unix
Source Code
Script & Languages
Protocols
Glossary
IGNOU
Quiz
About Us
Contact Us
Feedback
 
Sign up for our Email Newsletter
 
Get Paid for Your Tech Turorials / Tips

 

 

Home > Source Code > C Program Shell Script
Page : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
C Program Shell Script
 
/* 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

 
Page : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19