コード例 #1
0
ファイル: Base2.cs プロジェクト: olgk/systemutilities
 public Base2(decimal Bytes)
 {
     bits       = 0;
     storeMode  = Base2StorageMode.Bytes;
     parseMode  = Base2ParseMode.Binary;
     this.Bytes = Bytes;
 }
コード例 #2
0
ファイル: Base2.cs プロジェクト: olgk/systemutilities
 public static bool TryParse(string Value, Base2ParseMode ParseMode, bool Round, out Base2 Return)
 {
     try
     {
         Return = Parse(Value, ParseMode, Round);
     }
     catch
     {
         Return = new Base2(0);
         return(false);
     }
     return(true);
 }
コード例 #3
0
ファイル: Base2.cs プロジェクト: olgk/systemutilities
        public static Base2 Parse(string Value, Base2ParseMode ParseMode, bool Round)
        {
            var ret = new Base2();
            var r   = new System.Text.RegularExpressions.Regex(@"[A-Za-z]*$");

            if (Value.EndsWith("bit", StringComparison.CurrentCultureIgnoreCase))
            {
                ret.Bits = Convert.ToUInt64(r.Replace(Value, ""));
            }
            if (Value.EndsWith("B", StringComparison.CurrentCultureIgnoreCase))
            {
                try { ret.Bytes = Convert.ToInt64(r.Replace(Value, "")); }
                catch { Value += "B"; }
            }

            if (ParseMode == Base2ParseMode.Binary)
            {
                if (Value.EndsWith("KBIT", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Kibibits = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Kibibits = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("KB", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Kibibytes = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Kibibytes = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("MBIT", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Mebibits = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Mebibits = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("MB", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Mebibytes = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Mebibytes = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("GBIT", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Gibibits = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Gibibits = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("GB", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Gibibytes = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Gibibytes = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("TBIT", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Tebibits = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Tebibits = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("TB", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Tebibytes = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Tebibytes = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("PBIT", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Pebibits = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Pebibits = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("PB", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Pebibytes = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Pebibytes = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
            }

            if (ParseMode == Base2ParseMode.Scientific)
            {
                if (Value.EndsWith("KIBIT", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Kibibits = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Kibibits = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("KIB", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Kibibytes = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Kibibytes = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("MIBIT", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Mebibits = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Mebibits = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("MIB", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Mebibytes = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Mebibytes = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("GIBIT", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Gibibits = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Gibibits = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("GIB", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Gibibytes = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Gibibytes = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("TIBIT", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Tebibits = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Tebibits = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("TIB", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Tebibytes = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Tebibytes = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("PIBIT", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Pebibits = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Pebibits = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("PIB", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Pebibytes = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Pebibytes = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("KBIT", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Kilobits = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Kilobits = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("KB", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Kilobytes = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Kilobytes = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("MBIT", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Megabits = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Megabits = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("MB", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Megabytes = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Megabytes = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("GBIT", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Gigabits = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Gigabits = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("GB", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Gigabytes = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Gigabytes = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("TBIT", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Terabits = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Terabits = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("TB", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Terabytes = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Terabytes = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("PBIT", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Petabits = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Petabits = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
                if (Value.EndsWith("PB", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Round)
                    {
                        ret.Petabytes = Decimal.Round(Convert.ToDecimal(r.Replace(Value, "")));
                    }
                    else
                    {
                        ret.Petabytes = Convert.ToDecimal(r.Replace(Value, ""));
                    }
                }
            }

            ret.parseMode = ParseMode;
            return(ret);
        }
コード例 #4
0
ファイル: Base2.cs プロジェクト: olgk/systemutilities
 public Base2(ulong Bits)
 {
     bits      = Bits;
     storeMode = Base2StorageMode.Bits;
     parseMode = Base2ParseMode.Binary;
 }
コード例 #5
0
ファイル: Base2.cs プロジェクト: ellipticbit/systemutilities
		public Base2(decimal Bytes)
		{
			bits = 0;
			storeMode = Base2StorageMode.Bytes;
			parseMode = Base2ParseMode.Binary;
			this.Bytes = Bytes;
		}
コード例 #6
0
ファイル: Base2.cs プロジェクト: ellipticbit/systemutilities
		public Base2(ulong Bits)
		{
			bits = Bits;
			storeMode = Base2StorageMode.Bits;
			parseMode = Base2ParseMode.Binary;
		}
コード例 #7
0
ファイル: Base2.cs プロジェクト: ellipticbit/systemutilities
		public static Base2 Parse(string Value, Base2ParseMode ParseMode, bool Round)
		{
			var ret = new Base2();
			var r = new System.Text.RegularExpressions.Regex(@"[A-Za-z]*$");

			if (Value.EndsWith("bit", StringComparison.CurrentCultureIgnoreCase))
			{
				ret.Bits = Convert.ToUInt64(r.Replace(Value, ""));
			}
			if (Value.EndsWith("B", StringComparison.CurrentCultureIgnoreCase))
			{
				try { ret.Bytes = Convert.ToInt64(r.Replace(Value, "")); }
				catch { Value += "B"; }
			}

			if (ParseMode == Base2ParseMode.Binary)
			{
				if (Value.EndsWith("KBIT", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Kibibits = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Kibibits = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("KB", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Kibibytes = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Kibibytes = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("MBIT", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Mebibits = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Mebibits = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("MB", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Mebibytes = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Mebibytes = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("GBIT", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Gibibits = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Gibibits = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("GB", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Gibibytes = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Gibibytes = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("TBIT", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Tebibits = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Tebibits = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("TB", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Tebibytes = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Tebibytes = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("PBIT", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Pebibits = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Pebibits = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("PB", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Pebibytes = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Pebibytes = Convert.ToDecimal(r.Replace(Value, ""));
				}
			}

			if (ParseMode == Base2ParseMode.Scientific)
			{
				if (Value.EndsWith("KIBIT", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Kibibits = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Kibibits = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("KIB", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Kibibytes = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Kibibytes = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("MIBIT", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Mebibits = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Mebibits = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("MIB", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Mebibytes = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Mebibytes = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("GIBIT", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Gibibits = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Gibibits = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("GIB", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Gibibytes = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Gibibytes = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("TIBIT", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Tebibits = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Tebibits = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("TIB", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Tebibytes = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Tebibytes = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("PIBIT", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Pebibits = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Pebibits = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("PIB", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Pebibytes = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Pebibytes = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("KBIT", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Kilobits = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Kilobits = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("KB", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Kilobytes = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Kilobytes = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("MBIT", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Megabits = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Megabits = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("MB", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Megabytes = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Megabytes = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("GBIT", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Gigabits = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Gigabits = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("GB", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Gigabytes = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Gigabytes = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("TBIT", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Terabits = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Terabits = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("TB", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Terabytes = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Terabytes = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("PBIT", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Petabits = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Petabits = Convert.ToDecimal(r.Replace(Value, ""));
				}
				if (Value.EndsWith("PB", StringComparison.CurrentCultureIgnoreCase))
				{
					if (Round)
						ret.Petabytes = Math.Round(Convert.ToDecimal(r.Replace(Value, "")), 0);
					else
						ret.Petabytes = Convert.ToDecimal(r.Replace(Value, ""));
				}
			}

			ret.parseMode = ParseMode;
			return ret;
		}
コード例 #8
0
ファイル: Base2.cs プロジェクト: ellipticbit/systemutilities
		public static bool TryParse(string Value, Base2ParseMode ParseMode, bool Round, out Base2 Return)
		{
			try
			{
				Return = Parse(Value, ParseMode, Round);
			}
			catch
			{
				Return = new Base2(0);
				return false;
			}
			return true;
		}