1. using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    namespace zSharp2008.zMath
    {
        class cMath
        {
            string error = string.Empty;
            public string Error
            {
                get
                {
                    return error;
                }
            }

            public string DecimalToBinary(string data)
            {
                string result = string.Empty;
                int rem = 0;
                try
                {
                    if (!IsNumeric(data))
                        error = "Invalid Value - This is not a numeric value";
                    else
                    {
                        int num = int.Parse(data);
                        while (num > 0)
                        {
                            rem = num % 2;
                            num = num / 2;
                            result = rem.ToString() + result;
                        }
                    }
                }
                catch (Exception ex)
                {
                    error = ex.Message;
                }
                return result;
            }
            private bool IsNumeric(string number)
            {
                bool result = false;
                try
                {
                    int temp = int.Parse(number);
                    result = true;
                }
                catch (Exception ex)
                {
                    //Do nothing.
                }
                return result;
            }
        }
    }
    0

    Add a comment

Blog Archive
Topics
Topics
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.