Mono Class Library: System.Decimal Overview | Members

System.Decimal.GetBits Method

Returns a binary representation of the specified decimal value.

public static int[] GetBits (decimal d)

Parameters

d
The decimal value for which a binary representation is returned.

Returns

An array of four int containing an unspecified 128-bit representation of a decimal in its raw form.

Remarks

The format of the bits in the 4-element array returned is the same as that used by the bits parameter to decimal.Decimal(System.Int32) .

A numeric value can have several possible binary representations; they are numerically equal but have different scales. Also, the bit representation differentiates between -0, 0.00, and 0; these are all treated as 0 in operations, and any zero result will have a sign of 0.

Example

The following example demonstrates the different representations of 1.00 and 1.

C# Example

using System;
public class Class1  {
    public static void Print (int [] bs) {
        foreach (int b in bs) {
            Console.Write (b+" ");
        }
    }
public static void Main () {
   decimal d = 1.00m;
    decimal d1 = 1;
    Console.Write (d);
    Console.Write (" - bits: "); 
    Print (decimal.GetBits(d));
    Console.WriteLine();
    Console.Write (d1);
    Console.Write (" - bits: "); 
    Print (decimal.GetBits(d1));
    Console.WriteLine();
    Console.WriteLine ("d1.CompareTo(d) == {0}", d1.CompareTo(d));
    Console.WriteLine ("d1 == d {0}", d1 == d);
}
}
   

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0