This document contains the source code for a program that converts numbers between different number systems. It takes in a number, base 1, and base 2 as input. It then converts the number from base 1 to decimal, and from decimal to base 2. Key aspects of the code include:
1. Validating the input number and bases are valid integers between 0-36.
2. Converting the input number from base 1 to decimal by iterating through each digit and raising the base to a power corresponding to the digit's position.
3. Converting the decimal number to base 2 by taking the modulus and dividing successive times by the new base, while adding the digits to a string in reverse order.
Python Notes for mca i year students osmania university.docx
Any number system to any number system convertor
1. /*
SUBJECT: FUNDAMENTAL COMPUTER ORGANIZATION
COURSE : MCA-1
ROLL NO: 20
COLLAGE : ROLLWALA COMPUTER CENTER,GUJRATUNIVERSITY
NAME : PATEL SANDOIPBHAID.
EMAIL: PATELSANDIP445566@GMAIL.COM
ASSIGNMENT
PRACTICAL2
*/
// programfor CONVERTANYNUMBER SYSTEM TO ANY NUMBER SYSTEM
#include<stdio.h>
#include<conio.h>
intvalidInt(chars[]){
inti,n=0;
for(i=0;s[i]!='0';i++){
//checkno validornot
if(s[i]<'0'|| s[i]>'9')
return-1;
//forconvertnumbertointeger
n*=10;
n+=s[i]-48;
2. }
returnn;
}
voidmain(){
char s[50],r[50],sr[50];
inti,j,k,l;
intb1,b2,n,b,pn;
floatn1;//nis decimal n1is floating
intflag,ch,point;//flagforchecknoisvalidor not / flag1for check.(point)
do{
n1=0;point=0;
flag=1;i=j=k=0;
ch=1;
s[0]=r[0]=sr[0]='0';
printf("ntPROGRAMFORANYNUMBER SYSTEM TO ANY NYMBER SYSTEM CONVERTIONn");
printf("nYOUHAVETOGIVE BASE1 ANDBASE2 THE NUMBER OF BASE 1 IS CONVERTEDINTO
BASE 2");
do{
printf("nenterbase 1:");scanf("%s",&s);
b1=validInt(s);
if(b1<0){
3. printf("nnERROR:INVALIDBASETRY AGAIN:");
getch();
}
if(b1>36){
printf("nERROR:MAXIMUMBASE CAN BE 36 TRY AGAIN:");
getch();
continue;
}
}while(b1<0||b1>36);
do{
printf("nenterbase 2:");scanf("%s",&s);
b2=validInt(s);
if(b2<0){
printf("nnERROR:INVALIDBASETRY AGAIN:");
getch();
}
if(b2>36){
printf("nERROR:MAXIMUMBASE CAN BE 36 TRY AGAIN:");
getch();
continue;
}
}while(b2<0||b2>36);
if(b1==b2){
4. printf("nERROR:BOTHBASEARE SAME TRY AGAIN:");
getch();
continue;
}
printf("enternumber:");scanf("%s",&s);
//forconvertstrings to a numberof base1 systemandthenconvertit intodecimal
n=0;
b=b1;
//checksize of numberinstrings
for(i=0;s[i]!='0';i++);
j=i-1;
l=0;
/*
if pointfoundlike
12.25
program dolike
52.12
case 2:
123.25 = 52.123
//bothare wrong i actuallyneeded
5. 52.12 =12.25 and 123.25 =25.321
my programdo like that
52.12=21.52 and123.45=54.123
so i needto reverse the output
*/
point=0;
k=0;
for(i=j;i>=0;i--){
if(s[i]=='.'){
if(point<1){
point++;
r[l++]=s[i];
continue;
}
else{
printf("n**ERROR:INVALIDNUMBER MULTIPLE FLOATING
POINTS..**",b1);
flag=0;
break;
}
}
//dontreverse value of floatingpoint
if(point)
r[l++]=s[k++];
else