/* Zmienia wyswietlana liczbe (w dowolnym systemie liczbowym w zaleznosci * od wybranej dlugosci slowa. Na wejsciu przyjmuje liczbe w systemie * dziesietnym. */ public void ChangeNumberBaseSystem(string decNumber, NumberBaseSystem fromBase, NumberBaseSystem goalBase) { switch (CurrentWordLength) { case WordLengths.QWORD: CurrentEquationState = Convert.ToString(Convert.ToInt64((long.Parse(decNumber)).ToString(), (int)fromBase), (int)goalBase).ToUpper(); break; case WordLengths.DWORD: CurrentEquationState = Convert.ToString(Convert.ToInt32(((int)(long.Parse(decNumber))).ToString(), (int)fromBase), (int)goalBase).ToUpper(); break; case WordLengths.WORD: CurrentEquationState = Convert.ToString(Convert.ToInt16(((short)(long.Parse(decNumber))).ToString(), (int)fromBase), (int)goalBase).ToUpper(); break; case WordLengths.BYTE: CurrentEquationState = Convert.ToString(Convert.ToSByte(((sbyte)(long.Parse(decNumber))).ToString(), (int)fromBase), (int)goalBase).ToUpper(); switch (CurrentNumberBaseSystem) { case NumberBaseSystem.Binary: if (CurrentEquationState.Length > 8) { CurrentEquationState = CurrentEquationState.Substring(CurrentEquationState.Length - 8); } break; case NumberBaseSystem.Decimal: break; case NumberBaseSystem.Hexadecimal: if (CurrentEquationState.Length > 2) { CurrentEquationState = CurrentEquationState.Substring(CurrentEquationState.Length - 2); } break; case NumberBaseSystem.Octal: break; } break; } UpdateDisplay(this, eUpdateArgs); }
/* Ustawia nowy system liczbowy */ public void ChangeBaseNumberSystem(string NumberSystem) { NumberBaseSystem previousBaseSystem = CurrentNumberBaseSystem; string tempNumber = ConvertNumberToDecimal(CurrentEquationState.ExtractLastNumberFromString(m_fSearchWithMinus)); CurrentNumberBaseSystem = (NumberBaseSystem)Enum.Parse(typeof(NumberBaseSystem), NumberSystem); switch (CurrentNumberBaseSystem) { case NumberBaseSystem.Binary: LockButtons(this, new MyEventArgs("Octal")); LockButtons(this, new MyEventArgs("Decimal")); LockButtons(this, new MyEventArgs("Hexadecimal")); m_fSearchWithMinus = false; break; case NumberBaseSystem.Octal: UnlockButtons(this, new MyEventArgs("Octal")); LockButtons(this, new MyEventArgs("Decimal")); LockButtons(this, new MyEventArgs("Hexadecimal")); m_fSearchWithMinus = false; break; case NumberBaseSystem.Decimal: UnlockButtons(this, new MyEventArgs("Octal")); UnlockButtons(this, new MyEventArgs("Decimal")); LockButtons(this, new MyEventArgs("Hexadecimal")); m_fSearchWithMinus = true; break; case NumberBaseSystem.Hexadecimal: UnlockButtons(this, new MyEventArgs("Octal")); UnlockButtons(this, new MyEventArgs("Decimal")); UnlockButtons(this, new MyEventArgs("Hexadecimal")); m_fSearchWithMinus = false; break; } ChangeNumberBaseSystem(tempNumber, NumberBaseSystem.Decimal, CurrentNumberBaseSystem); }