本文整理汇总了C#中System.Decimal.GetBits方法的典型用法代码示例。如果您正苦于以下问题:C# Decimal.GetBits方法的具体用法?C# Decimal.GetBits怎么用?C# Decimal.GetBits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Decimal
的用法示例。
在下文中一共展示了Decimal.GetBits方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
class Example
{
public static void Main()
{
// Define an array of Decimal values.
Decimal[] values = { 1M, 100000000000000M, 10000000000000000000000000000M,
100000000000000.00000000000000M, 1.0000000000000000000000000000M,
123456789M, 0.123456789M, 0.000000000123456789M,
0.000000000000000000123456789M, 4294967295M,
18446744073709551615M, Decimal.MaxValue,
Decimal.MinValue, -7.9228162514264337593543950335M };
Console.WriteLine("{0,31} {1,10:X8}{2,10:X8}{3,10:X8}{4,10:X8}",
"Argument", "Bits[3]", "Bits[2]", "Bits[1]",
"Bits[0]" );
Console.WriteLine( "{0,31} {1,10:X8}{2,10:X8}{3,10:X8}{4,10:X8}",
"--------", "-------", "-------", "-------",
"-------" );
// Iterate each element and display its binary representation
foreach (var value in values) {
int[] bits = decimal.GetBits(value);
Console.WriteLine("{0,31} {1,10:X8}{2,10:X8}{3,10:X8}{4,10:X8}",
value, bits[3], bits[2], bits[1], bits[0]);
}
}
}
输出:
Argument Bits[3] Bits[2] Bits[1] Bits[0] -------- ------- ------- ------- ------- 1 00000000 00000000 00000000 00000001 100000000000000 00000000 00000000 00005AF3 107A4000 10000000000000000000000000000 00000000 204FCE5E 3E250261 10000000 100000000000000.00000000000000 000E0000 204FCE5E 3E250261 10000000 1.0000000000000000000000000000 001C0000 204FCE5E 3E250261 10000000 123456789 00000000 00000000 00000000 075BCD15 0.123456789 00090000 00000000 00000000 075BCD15 0.000000000123456789 00120000 00000000 00000000 075BCD15 0.000000000000000000123456789 001B0000 00000000 00000000 075BCD15 4294967295 00000000 00000000 00000000 FFFFFFFF 18446744073709551615 00000000 00000000 FFFFFFFF FFFFFFFF 79228162514264337593543950335 00000000 FFFFFFFF FFFFFFFF FFFFFFFF -79228162514264337593543950335 80000000 FFFFFFFF FFFFFFFF FFFFFFFF -7.9228162514264337593543950335 801C0000 FFFFFFFF FFFFFFFF FFFFFFFF
示例2: Main
//引入命名空间
using System;
public class Example
{
public static void Main()
{
Decimal[] values = { 1234.96m, -1234.96m };
foreach (var value in values) {
int[] parts = Decimal.GetBits(value);
bool sign = (parts[3] & 0x80000000) != 0;
byte scale = (byte) ((parts[3] >> 16) & 0x7F);
Decimal newValue = new Decimal(parts[0], parts[1], parts[2], sign, scale);
Console.WriteLine("{0} --> {1}", value, newValue);
}
}
}
输出:
1234.96 --> 1234.96 -1234.96 --> -1234.96