static float Pow(int a, int x) { float result = 1; if (x > 0) for (int i = 0; i < x; i++) result *= a; else for (int i = x; i < 0; i++) result /= a; return result; }
static float BinMantToDec(string mant) { float decMant = 0; for (int i = 0; i < mant.Length; i++) if (mant[i] == '1') decMant += Pow(2, -(i + 1)); return decMant; }
static float BinAntjeToDec(string antje) { float decAntje = 0; for (int i = 0; i < antje.Length; i++) if (antje[i] == '1') decAntje += Pow(2, antje.Length - i - 1); return decAntje; }
static float BinToDec(string bin) { int indexSep = bin.IndexOf(',');
var a,b,c,i,n,p,s:integer; x:real; p1,g:string; begin writeln('vvedite chislo'); readln(a); writeln('is kakoi perevodim?'); readln(b); if b=10 then begin writeln('v kakoi perevodim?'); readln(c); end; n:=0; p:=0;
if b<>10 then begin 'is 10 v lubuyu sistemu repeat x:=exp(ln(b)*n); s:=Round(x); p:=p + (a mod 10)*s; a:= a div 10; n:=n+1; until a=0; end
else begin
repeat 'is luboi sistemi v 10 g:=IntToStr(a mod c); p1:=p1 + g; a:=a div c; until a<c; p1:=p1+IntToStr(a); end;
if p=0 then begin 'vivod for i:=1 to length(p1) do write(p1[length(p1)-i+1]); end else write(p); end.
static string DecAntjeToBin(int antje)
{
/*if (antje == 0)
return "0";*/ //косметический 0 перед запятой если целая часть равна 0
string bin = "";
while (antje != 0)
{
bin = (antje % 2).ToString() + bin;
antje /= 2;
}
return bin;
}
static string DecMantToBin(float mant, int precision)
{
/*if (mant == 0)
return "0";*/ //косметический 0 после запятой если дробная часть равна 0
string bin = "";
while (mant != 0 && bin.Length <= precision)
{
mant *= 2;
bin += ((int)mant).ToString();
mant -= (int)mant;
}
return bin;
}
static string DecToBin(float dec, int precision)
{
int antje = (int)dec;
float mant = dec - antje;
return DecAntjeToBin(antje) + "," + DecMantToBin(mant, precision);
}
static string DecToBin(int dec)
{
return DecAntjeToBin(dec);
}
static float Pow(int a, int x)
{
float result = 1;
if (x > 0)
for (int i = 0; i < x; i++)
result *= a;
else
for (int i = x; i < 0; i++)
result /= a;
return result;
}
static float BinMantToDec(string mant)
{
float decMant = 0;
for (int i = 0; i < mant.Length; i++)
if (mant[i] == '1')
decMant += Pow(2, -(i + 1));
return decMant;
}
static float BinAntjeToDec(string antje)
{
float decAntje = 0;
for (int i = 0; i < antje.Length; i++)
if (antje[i] == '1')
decAntje += Pow(2, antje.Length - i - 1);
return decAntje;
}
static float BinToDec(string bin)
{
int indexSep = bin.IndexOf(',');
if (indexSep == -1)
return BinAntjeToDec(bin);
string binAnt = bin.Substring(0, indexSep);
string binMant = bin.Substring(indexSep + 1);
return BinAntjeToDec(binAnt) + BinMantToDec(binMant);
}
var
a,b,c,i,n,p,s:integer;
x:real;
p1,g:string;
begin
writeln('vvedite chislo');
readln(a);
writeln('is kakoi perevodim?');
readln(b);
if b=10 then begin
writeln('v kakoi perevodim?');
readln(c);
end;
n:=0;
p:=0;
if b<>10 then begin 'is 10 v lubuyu sistemu
repeat
x:=exp(ln(b)*n);
s:=Round(x);
p:=p + (a mod 10)*s;
a:= a div 10;
n:=n+1;
until a=0;
end
else begin
repeat 'is luboi sistemi v 10
g:=IntToStr(a mod c);
p1:=p1 + g;
a:=a div c;
until a<c;
p1:=p1+IntToStr(a);
end;
if p=0 then begin 'vivod
for i:=1 to length(p1) do
write(p1[length(p1)-i+1]);
end
else
write(p);
end.