Decimal.GetBits()方法用于将Decimal的指定实例的值转换为其等效的二进制表示形式。
Syntax: public static int[] GetBits (decimal d);
Here, it takes the floating point value to convert.
Return Value: This method returns a 32-bit signed integer array with four elements that contain the binary representation of d.
下面的程序说明了Decimal.GetBits()方法的用法
范例1:
// C# program to demonstrate the
// Decimal.GetBits() Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing value
decimal value = 18446744073709551615M;
// getting Equivalent bit
// using GetBits() method
int[] arr = Decimal.GetBits(value);
// Display the element
for (int i = 0; i < arr.Length; i++)
Console.WriteLine("Bit[{0}] = {1, 10:X8}",
i, arr[i]);
}
}
输出:
Bit[0] = FFFFFFFF
Bit[1] = FFFFFFFF
Bit[2] = 00000000
Bit[3] = 00000000
范例2:
// C# program to demonstrate the
// Decimal.GetBits() Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// calling get() method
get(Decimal.MaxValue);
Console.WriteLine("");
get(Decimal.MinValue);
}
// defining get() method
public static void get(decimal value)
{
// getting Equivalent bit
// using GetBits() method
Console.WriteLine("Converted value of {0} is",
value);
int[] arr = Decimal.GetBits(value);
// Display the element
for (int i = 0; i < arr.Length; i++)
Console.WriteLine("Bit[{0}] = {1, 10:X8}",
i, arr[i]);
}
}
输出:
Converted value of 79228162514264337593543950335 is
Bit[0] = FFFFFFFF
Bit[1] = FFFFFFFF
Bit[2] = FFFFFFFF
Bit[3] = 00000000
Converted value of -79228162514264337593543950335 is
Bit[0] = FFFFFFFF
Bit[1] = FFFFFFFF
Bit[2] = FFFFFFFF
Bit[3] = 80000000
参考:
- https://docs.microsoft.com/zh-cn/dotnet/api/system.decimal.getbits?view=netframework-4.7.2