Search Results for

    Show / Hide Table of Contents

    Struct FourBitNumber

    Type that is used to represent a four-bit number (0-15; or in binary format 0000-1111).
    Implements
    IComparable<FourBitNumber>
    IConvertible
    Inherited Members
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Melanchall.DryWetMidi.Common
    Assembly: Melanchall.DryWetMidi.dll
    Syntax
    public struct FourBitNumber : IComparable<FourBitNumber>, IConvertible
    Remarks
    Four-bit numbers widely used by MIDI protocol as parameters of MIDI events (channel number, for example). Instead of manipulating built-in .NET numeric types (like byte or int) and checking for out-of-range errors all validation of numbers in the [0; 15] range happens on data type level via casting .NET integer values to the FourBitNumber (see explicit operator FourBitNumber(byte)).
    Examples

    For example, to set a note's channel:

    var noteOnEvent = new NoteOnEvent();
    noteOnEvent.Channel = (FourBitNumber)10;

    Constructors

    FourBitNumber(byte)

    Initializes a new instance of the FourBitNumber with the specified value.
    Declaration
    public FourBitNumber(byte value)
    Parameters
    Type Name Description
    byte value Value representing four-bit number.
    Exceptions
    Type Condition
    ArgumentOutOfRangeException value is out of [MinValue; MaxValue] range.

    Fields

    MaxValue

    The largest possible value of a FourBitNumber.
    Declaration
    public static readonly FourBitNumber MaxValue
    Field Value
    Type Description
    FourBitNumber

    MinValue

    The smallest possible value of a FourBitNumber.
    Declaration
    public static readonly FourBitNumber MinValue
    Field Value
    Type Description
    FourBitNumber

    Values

    All possible values of FourBitNumber.
    Declaration
    public static readonly FourBitNumber[] Values
    Field Value
    Type Description
    FourBitNumber[]

    Methods

    CompareTo(FourBitNumber)

    Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
    Declaration
    public int CompareTo(FourBitNumber other)
    Parameters
    Type Name Description
    FourBitNumber other An object to compare with this instance.
    Returns
    Type Description
    int

    A value that indicates the relative order of the objects being compared. The return value has these meanings:

    ValueMeaning
    Less than zeroThis instance precedes other in the sort order.
    ZeroThis instance occurs in the same position in the sort order as other.
    Greater than zeroThis instance follows other in the sort order.

    Equals(object)

    Determines whether the specified object is equal to the current object.
    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    object obj The object to compare with the current object.
    Returns
    Type Description
    bool true if the specified object is equal to the current object; otherwise, false.
    Overrides
    ValueType.Equals(object)

    GetHashCode()

    Serves as the default hash function.
    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int A hash code for the current object.
    Overrides
    ValueType.GetHashCode()

    GetTypeCode()

    Returns the TypeCode for value type FourBitNumber.
    Declaration
    public TypeCode GetTypeCode()
    Returns
    Type Description
    TypeCode The enumerated constant, Byte.

    Parse(string)

    Converts the string representation of a four-bit number to its FourBitNumber equivalent.
    Declaration
    public static FourBitNumber Parse(string input)
    Parameters
    Type Name Description
    string input A string containing a number to convert.
    Returns
    Type Description
    FourBitNumber A FourBitNumber equivalent to the four-bit number contained in input.
    Exceptions
    Type Condition
    ArgumentException input is null or contains white-spaces only.
    FormatException input has invalid format.

    ToString()

    Returns a string that represents the current object.
    Declaration
    public override string ToString()
    Returns
    Type Description
    string A string that represents the current object.
    Overrides
    ValueType.ToString()

    TryParse(string, out FourBitNumber)

    Converts the string representation of a four-bit number to its FourBitNumber equivalent. A return value indicates whether the conversion succeeded.
    Declaration
    public static bool TryParse(string input, out FourBitNumber fourBitNumber)
    Parameters
    Type Name Description
    string input A string containing a number to convert.
    FourBitNumber fourBitNumber When this method returns, contains the FourBitNumber equivalent of the four-bit number contained in input, if the conversion succeeded, or zero if the conversion failed. The conversion fails if the input is null or Empty, or is not of the correct format. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.
    Returns
    Type Description
    bool true if input was converted successfully; otherwise, false.

    Operators

    explicit operator FourBitNumber(byte)

    Converts the value of a byte to a FourBitNumber.
    Declaration
    public static explicit operator FourBitNumber(byte number)
    Parameters
    Type Name Description
    byte number Byte value to convert to a FourBitNumber object.
    Returns
    Type Description
    FourBitNumber number represented as FourBitNumber.
    Exceptions
    Type Condition
    ArgumentOutOfRangeException number is out of [0; 15] range.

    implicit operator byte(FourBitNumber)

    Converts the value of a FourBitNumber to a byte.
    Declaration
    public static implicit operator byte(FourBitNumber number)
    Parameters
    Type Name Description
    FourBitNumber number FourBitNumber object to convert to a byte value.
    Returns
    Type Description
    byte number represented as byte.

    Implements

    IComparable<T>
    IConvertible
    In this article
    Back to top 2024 / Generated by DocFX