forked from hellzerg/optimizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BinaryByteSize.cs
86 lines (71 loc) · 2.57 KB
/
BinaryByteSize.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Globalization;
namespace Optimizer
{
public partial struct ByteSize
{
public const long BytesInKibiByte = 1_024;
public const long BytesInMebiByte = 1_048_576;
public const long BytesInGibiByte = 1_073_741_824;
public const long BytesInTebiByte = 1_099_511_627_776;
public const long BytesInPebiByte = 1_125_899_906_842_624;
public const string KibiByteSymbol = "KiB";
public const string MebiByteSymbol = "MiB";
public const string GibiByteSymbol = "GiB";
public const string TebiByteSymbol = "TiB";
public const string PebiByteSymbol = "PiB";
public double KibiBytes => Bytes / BytesInKibiByte;
public double MebiBytes => Bytes / BytesInMebiByte;
public double GibiBytes => Bytes / BytesInGibiByte;
public double TebiBytes => Bytes / BytesInTebiByte;
public double PebiBytes => Bytes / BytesInPebiByte;
public static ByteSize FromKibiBytes(double value)
{
return new ByteSize(value * BytesInKibiByte);
}
public static ByteSize FromMebiBytes(double value)
{
return new ByteSize(value * BytesInMebiByte);
}
public static ByteSize FromGibiBytes(double value)
{
return new ByteSize(value * BytesInGibiByte);
}
public static ByteSize FromTebiBytes(double value)
{
return new ByteSize(value * BytesInTebiByte);
}
public static ByteSize FromPebiBytes(double value)
{
return new ByteSize(value * BytesInPebiByte);
}
public ByteSize AddKibiBytes(double value)
{
return this + ByteSize.FromKibiBytes(value);
}
public ByteSize AddMebiBytes(double value)
{
return this + ByteSize.FromMebiBytes(value);
}
public ByteSize AddGibiBytes(double value)
{
return this + ByteSize.FromGibiBytes(value);
}
public ByteSize AddTebiBytes(double value)
{
return this + ByteSize.FromTebiBytes(value);
}
public ByteSize AddPebiBytes(double value)
{
return this + ByteSize.FromPebiBytes(value);
}
public string ToBinaryString()
{
return this.ToString("0.##", CultureInfo.CurrentCulture, useBinaryByte: true);
}
public string ToBinaryString(IFormatProvider formatProvider)
{
return this.ToString("0.##", formatProvider, useBinaryByte: true);
}
}
}