Class BinaryPrefix
Defines a binary unit prefix for multiples of measurement for data that refers strictly to powers of 2. This class cannot be inherited.
Examples
Work with binary prefixes (kibi, mebi, gibi, etc.) for data storage measurements. This example retrieves binary prefix constants, demonstrates property access to find their symbols and multiplier values, converts raw byte values to binary scales using ToPrefixValue(), and shows how to construct PrefixUnit objects that combine a unit with a binary prefix:
using System;
using Codebelt.Unitify;
namespace Unitify.Samples;
public class BinaryPrefixExample
{
public static void Main()
{
// Get the kibi prefix (2^10)
var kibi = BinaryPrefix.Kibi;
Console.WriteLine($"Kibi symbol: {kibi.Symbol}");
Console.WriteLine($"Kibi multiplier: {kibi.Multiplier}");
// Work with data prefix values
var bytes = 1024.0;
var kibibytes = kibi.ToPrefixValue(bytes); // Convert to kibi scale
Console.WriteLine($"{bytes} bytes = {kibibytes} KiB");
// Create a base unit value with binary prefix
var dataUnit = new PrefixUnit(Unit.Byte, 1048576, BinaryPrefix.Mebi); // 1 MiB
Console.WriteLine($"Data unit: {dataUnit}");
}
}
public sealed class BinaryPrefix : Prefix, IPrefix
- Inheritance
-
BinaryPrefix
- Implements
- Inherited Members
- Extension Methods
Constructors
BinaryPrefix(string, string, double)
Initializes a new instance of the BinaryPrefix class.
public BinaryPrefix(string name, string symbol, double exponent)
Parameters
namestringThe name of the binary prefix.
symbolstringThe symbol of the binary prefix.
exponentdoubleThe number that specifies a power.
Fields
BitsPerByte
Defines how many bits is needed for one byte.
public const int BitsPerByte = 8
Field Value
BitsPerNibble
Defines how many bits is needed for one nibble (one hexadecimal digit).
public const int BitsPerNibble = 4
Field Value
Properties
BinaryPrefixes
Gets the complete sequence of multiples binary prefixes as specified by IEC 80000-13:2025, covering kibi (2^10) through quebi (2^100).
public static IEnumerable<BinaryPrefix> BinaryPrefixes { get; }
Property Value
- IEnumerable<BinaryPrefix>
The complete sequence of multiples binary prefixes as specified by IEC 80000-13:2025.
Exbi
Gets the binary-multiple prefix exbi (symbol 'Ei'), 2^60 = 1152921504606846976.
public static BinaryPrefix Exbi { get; }
Property Value
- BinaryPrefix
The binary-multiple prefix exbi (symbol 'Ei').
Gibi
Gets the binary-multiple prefix gibi (symbol 'Gi'), 2^30 = 1073741824.
public static BinaryPrefix Gibi { get; }
Property Value
- BinaryPrefix
The binary-multiple prefix gibi (symbol 'Gi').
Kibi
Gets the binary-multiple prefix kibi (symbol 'Ki'), 2^10 = 1024.
public static BinaryPrefix Kibi { get; }
Property Value
- BinaryPrefix
The binary-multiple prefix kibi (symbol 'Ki').
Mebi
Gets the binary-multiple prefix mebi (symbol 'Mi'), 2^20 = 1048576.
public static BinaryPrefix Mebi { get; }
Property Value
- BinaryPrefix
The binary-multiple prefix mebi (symbol 'Mi').
Pebi
Gets the binary-multiple prefix pebi (symbol 'Pi'), 2^50 = 1125899906842624.
public static BinaryPrefix Pebi { get; }
Property Value
- BinaryPrefix
The binary-multiple prefix pebi (symbol 'Pi').
Quebi
Gets the binary-multiple prefix quebi (symbol 'Qi'), 2^100 = 1267650600228229401496703205376.
public static BinaryPrefix Quebi { get; }
Property Value
- BinaryPrefix
The binary-multiple prefix quebi (symbol 'Qi').
Robi
Gets the binary-multiple prefix robi (symbol 'Ri'), 2^90 = 1237940039285380274899124224.
public static BinaryPrefix Robi { get; }
Property Value
- BinaryPrefix
The binary-multiple prefix robi (symbol 'Ri').
Tebi
Gets the binary-multiple prefix tebi (symbol 'Ti'), 2^40 = 1099511627776.
public static BinaryPrefix Tebi { get; }
Property Value
- BinaryPrefix
The binary-multiple prefix tebi (symbol 'Ti').
Yobi
Gets the binary-multiple prefix yobi (symbol 'Yi'), 2^80 = 1208925819614629174706176.
public static BinaryPrefix Yobi { get; }
Property Value
- BinaryPrefix
The binary-multiple prefix yobi (symbol 'Yi').
Zebi
Gets the binary-multiple prefix zebi (symbol 'Zi'), 2^70 = 1180591620717411303424.
public static BinaryPrefix Zebi { get; }
Property Value
- BinaryPrefix
The binary-multiple prefix zebi (symbol 'Zi').
Methods
ConvertBitsToBytes(double)
Converts a value in bits to bytes.
public static double ConvertBitsToBytes(double bits)
Parameters
bitsdoubleThe value in bits to convert.
Returns
- double
The equivalent value in bytes.
ConvertBytesToBits(double)
Converts a value in bytes to bits.
public static double ConvertBytesToBits(double bytes)
Parameters
bytesdoubleThe value in bytes to convert.
Returns
- double
The equivalent value in bits.
Exceptions
- ArgumentOutOfRangeException
bytesis less than 0.