Exemplo n.º 1
0
 public static double BreakDownBitRate(long rate, out BitByteUnit unit)
 {
     if (rate < 1024)
     {
         unit = BitByteUnit.Bit;
         return(rate);
     }
     else if (rate < Math.Pow(1000, 2))
     {
         unit = BitByteUnit.KBit;
         return(rate / 1000);
     }
     else if (rate < Math.Pow(1000, 3))
     {
         unit = BitByteUnit.MBit;
         return(rate / Math.Pow(1000, 2));
     }
     else
     {
         unit = BitByteUnit.GBit;
         return(rate / Math.Pow(1000, 3));
     }
 }
Exemplo n.º 2
0
        public static long BrokenDownRateToBitRate(double rate, BitByteUnit unit)
        {
            switch (unit)
            {
            case BitByteUnit.Bit: return((long)rate);

            case BitByteUnit.Byte: return((long)(rate * 8));

            case BitByteUnit.KBit: return((long)(rate * 1000));

            case BitByteUnit.KByte: return((long)(rate * 1024 * 8));

            case BitByteUnit.MBit: return((long)(rate * Math.Pow(1000, 2)));

            case BitByteUnit.MByte: return((long)(rate * Math.Pow(1024, 2) * 8));

            case BitByteUnit.GBit: return((long)(rate * Math.Pow(1000, 3)));

            case BitByteUnit.GByte: return((long)(rate * Math.Pow(1024, 3) * 8));

            default:
                throw new Exception("BitByteUnit missing");
            }
        }