Zdravim ...
mam takovy problem upravoval jsem si scp na prevadeni cisel desetinyho cisla do ostatnich soustav ale narazil jsme na porblem ale bohuzel ten jaksi neumim opravit ... jde o chyby pri spousteni fce v algorytmu
http://koukej.707.cz/obrazky/.......jpg
Poradi mi nekdo ?
Jinak dalsi otazka ... Nevite jak muzu udelat algorytmus na desetiny mista v Octal , Bin a Hex do Decu ? Diky moc
Fórum › .NET
Algorytmus na des. cisla [Převod]

To Odin :
minule som robil z bin to dec ...neviem sice ci to mam najefektivnejsim sposobom ale priu x pokusoch to vyzeralo, ze to funguje ako ma
public static int Bin2Dec(int cislo2)
{
binaryNumber = ObratRetazec(cislo2.ToString());
int medziSucet = 0;
int znak;
for (int i = 0; i < cislo2.ToString().Length; i++)
{
znak = int.Parse(binaryNumber[i].ToString());
medziSucet = 0;
medziSucet = MatematickeOperacie.NaXTu(2, i);
decimalNumber = decimalNumber + (znak * medziSucet);
}
return decimalNumber;
public static string ObratRetazec(string reatazec)
{
string vysledok = "";
for (int i = reatazec.Length - 1; i >= 0; i--)
{
vysledok = vysledok + reatazec[i];
}
return vysledok;
public static int NaXTu(int coNaXTu, int exponent)
{
int vysledok = coNaXTu;
if (exponent == 0) { return 1; }
if (exponent == 1) { return coNaXTu; }
for (int i = 2; i <= exponent; i++)
{
vysledok = vysledok * coNaXTu;
}
return vysledok;
}
Zamysli se nad tím, co číslice v číslech znamenají.
1234 dec: (1*1000) + (2*100) + (3*10) + (4*1) = (1 * 10^3) + (2 * 10^2) + (3 * 10^1) + (4 * 10^0) = 1234 dec
4567 oct: (4* 512) + (5* 64) + (6* 8) + (7*1) = (4 * 8^3) + (5 * 8^2) + (6 * 8^1) + (7 * 8^0) = 2423 dec
1011 bin: (1* 8) + (0* 4) + (2* 2) + (1*1) = (1 * 2^3) + (0 * 2^2) + (1 * 2^1) + (1 * 2^0) = 11 dec
Vidíš tam to (číslice*základ^pozice) ? Takhle převedeš cokoliv a opačný směr si z toho snad už domyslíš.
PS: A protože ti to ještě asi nikdo neřekl, tak tě k uvědomění navedu já. Ten zdroják je hnus a za neustálé pojmenovávání proměnných jako 'vypocet' se budeš smažit v pekle :)
Co delam v tomto kodu blbe ?
¨float NumberOthers;
public void OthersToDecDesCislo(int number, int cislo_nasobit)
{
int Length_TextBox = des_carka.Text.Length;
float Nasob;
int index = -1;
int number_rozdeleno;
for(int i = 1; Length_TextBox > i; i++)
{
number_rozdeleno = Int32.Parse(number.ToString()[i].ToString());
Nasob = (float)Math.Pow(number_rozdeleno, index);
index = index - 1;
NumberOthers = NumberOthers + Nasob;
}
Dec_End2.Text = NumberOthers.ToString();
}
int DigToInt(char Dig, int Base)
{
return int.Parse(Dig.ToString(), System.Globalization.NumberStyles.HexNumber);
}
decimal StrToDec(string Str, int Base)
{
decimal num = 0;
int index = (Str + ".").IndexOf(".") - 1;
for (int i = 0; i < Str.Length; i++) {
if (Str[i] == '.')
continue;
num += DigToInt(Str[i], Base) * (decimal)Math.Pow(Base, index--);
}
return num;
}

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 33 hostů
Podobná vlákna
Převod z čísla do znaku — založil Jan Růžička
Převod písmen na čísla — založil Merlin
Prevod cisla na retazec — založil olgo
Převod dekadického čísla na binární — založil Liliputan
Převod čísla z hexa do decimal — založil viky
Moderátoři diskuze