public override Binary ToBinary() { Convertor bc = new BinConvertor(_bin); if (bc.ToString() is null || bc.ToString() == "" || bc.ToString().Length == 0) { throw new ArgumentNullException(); } return(new Binary(_bin)); }
/// <summary> /// This method converts the number to the respective numbertype selected by the user /// </summary> /// <param name="sourceType">Source of the number type</param> /// <param name="number">Number entered by the user</param> /// <param name="targetType">Target of the number type</param> /// <returns>Number Object - Converted number</returns> public Number Convert(NumberType sourceType, Number number, NumberType targetType) { BinConvertor b = new BinConvertor(number.ToString()); HexConvertor h = new HexConvertor(number.ToString()); OctConvertor o = new OctConvertor(number.ToString()); if (sourceType == Numbers.NumberType.Binary && targetType == Numbers.NumberType.Binary) { return(b.ToBinary()); } if (sourceType == Numbers.NumberType.Binary && targetType == Numbers.NumberType.Hexadecimal) { return(b.ToHexadecimal()); } if (sourceType == Numbers.NumberType.Binary && targetType == Numbers.NumberType.Octal) { return(b.ToOctal()); } if (sourceType == Numbers.NumberType.Hexadecimal && targetType == Numbers.NumberType.Binary) { return(h.ToBinary()); } if (sourceType == Numbers.NumberType.Hexadecimal && targetType == Numbers.NumberType.Hexadecimal) { return(h.ToHexadecimal()); } if (sourceType == Numbers.NumberType.Octal && targetType == Numbers.NumberType.Binary) { return(o.ToBinary()); } if (sourceType == Numbers.NumberType.Octal && targetType == Numbers.NumberType.Octal) { return(o.ToOctal()); } else { return(null); } }
public override Hexadecimal ToHexadecimal() { Convertor bc = new BinConvertor(_bin); if (bc.ToString() is null || bc.ToString() == "" || bc.ToString().Length == 0) { throw new ArgumentNullException(); } string b = ConvertToBinArray1(bc.ToString()); string[] binArray = Split1(b, 4); string result = ""; foreach (string s in binArray) { if (Hex2Binary.ContainsKey(s)) { result += Hex2Binary[s]; } } return(new Hexadecimal(result)); }
public override Octal ToOctal() { Convertor bc = new BinConvertor(_bin); if (bc.ToString() is null || bc.ToString() == "" || bc.ToString().Length == 0) { throw new ArgumentNullException(); } string b = ConvertToBinArray(bc.ToString()); string[] binArray = Split1(b, 3); string result = ""; foreach (string s in binArray) { if (Bin2Oct.ContainsKey(s)) { result += Bin2Oct[s]; } } return(new Octal(result)); }