Exemplo n.º 1
0
 private void ApplyInput()
 {
     try
     {
         bool            useLong = cbUseLong.Checked;
         TenHexConverter th      = useLong ? TenHexConverter.ParseLong(tbInput.Text, _inputType) : TenHexConverter.Parse(tbInput.Text, _inputType);
         lblErr.Text = String.Empty;
         lblBin.Text = th.BinValue;
         lblOct.Text = th.OctValue;
         lblDec.Text = th.DecimalValue;
         lblHex.Text = th.HexValue;
     }
     catch (Exception ex)
     {
         lblBin.Text = lblOct.Text = lblDec.Text = lblHex.Text = String.Empty;
         lblErr.Text = ex.Message;
     }
 }
Exemplo n.º 2
0
    private void ApplyInput()
    {
        InputType it = GetInputType();

        lblInput.Text = String.Format("Enter {0} Value:", it);
        string input   = tbInput.Text;
        bool   useLong = cbLong.Checked;

        try
        {
            TenHexConverter tc = useLong ? TenHexConverter.ParseLong(input, it) : TenHexConverter.Parse(input, it);
            errMsg.Text = String.Empty;
            lblHex.Text = tc.HexValue;
            lblDec.Text = tc.DecimalValue;
            lblOct.Text = tc.OctValue;
            lblBin.Text = tc.BinValue;
        }
        catch (Exception ex)
        {
            lblHex.Text = lblDec.Text = lblOct.Text = lblBin.Text = String.Empty;
            errMsg.Text = ex.Message;
        }
    }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            ShowUsage();

            InputType       inputType    = InputType.Decimal;
            Action <string> setInputType = (ss) =>
            {
                if (String.IsNullOrEmpty(ss))
                {
                    return;
                }
                switch (Char.ToLower(ss[0]))
                {
                case 'd': inputType = InputType.Decimal; break;

                case 'h': inputType = InputType.HexaDecimal; break;

                case 'o': inputType = InputType.Octal; break;

                case 'b':       inputType = InputType.Binary; break;
                }
            };

            if (args.Length > 0)
            {
                setInputType(args[0]);
            }
            while (true)
            {
                Console.Write($"Enter {inputType} value: ");
                string input = Console.ReadLine();
                if (input.Length == 1 && Char.IsLetter(input[0]))
                {
                    if (Char.ToLower(input[0]) == 'q')
                    {
                        break;
                    }
                    setInputType(input);
                    continue;
                }
                try
                {
                    TenHexConverter th = TenHexConverter.Parse(input, inputType);
                    Console.ForegroundColor = ConsoleColor.Green;                       // indicate success
                    if (inputType != InputType.HexaDecimal)
                    {
                        Console.WriteLine($"Hex: {th.HexValue}");
                    }
                    if (inputType != InputType.Decimal)
                    {
                        Console.WriteLine($"Dec: {th.DecimalValue}");
                    }
                    if (inputType != InputType.Octal)
                    {
                        Console.WriteLine($"Oct: {th.OctValue}");
                    }
                    if (inputType != InputType.Binary)
                    {
                        Console.WriteLine($"Bin: {th.BinValue}");
                    }
                    Console.ResetColor();
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;                         // indicate failure
                    Console.WriteLine($"Conversion failed: {ex.Message}");
                    Console.ResetColor();
                }
            }
        }