Table of Contents

BinaryPrefix Class

Definition

Namespace
Codebelt.Unitify
Assemblies
Codebelt.Unitify.dll
Source
src/Codebelt.Unitify/BinaryPrefix.cs

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

Name Description
BinaryPrefix(string, string, double)

Initializes a new instance of the BinaryPrefix class.

Fields

Name Description
BitsPerByte

Defines how many bits is needed for one byte.

BitsPerNibble

Defines how many bits is needed for one nibble (one hexadecimal digit).

Properties

Name Description
BinaryPrefixes

Gets the complete sequence of multiples binary prefixes as specified by IEC 80000-13:2025, covering kibi (2^10) through quebi (2^100).

Exbi

Gets the binary-multiple prefix exbi (symbol 'Ei'), 2^60 = 1152921504606846976.

Gibi

Gets the binary-multiple prefix gibi (symbol 'Gi'), 2^30 = 1073741824.

Kibi

Gets the binary-multiple prefix kibi (symbol 'Ki'), 2^10 = 1024.

Mebi

Gets the binary-multiple prefix mebi (symbol 'Mi'), 2^20 = 1048576.

Pebi

Gets the binary-multiple prefix pebi (symbol 'Pi'), 2^50 = 1125899906842624.

Quebi

Gets the binary-multiple prefix quebi (symbol 'Qi'), 2^100 = 1267650600228229401496703205376.

Robi

Gets the binary-multiple prefix robi (symbol 'Ri'), 2^90 = 1237940039285380274899124224.

Tebi

Gets the binary-multiple prefix tebi (symbol 'Ti'), 2^40 = 1099511627776.

Yobi

Gets the binary-multiple prefix yobi (symbol 'Yi'), 2^80 = 1208925819614629174706176.

Zebi

Gets the binary-multiple prefix zebi (symbol 'Zi'), 2^70 = 1180591620717411303424.

Methods

Name Description
ConvertBitsToBytes(double)

Converts a value in bits to bytes.

ConvertBytesToBits(double)

Converts a value in bytes to bits.

See Also