本文整理匯總了C#中System.BitConverter.ToBoolean方法的典型用法代碼示例。如果您正苦於以下問題:C# BitConverter.ToBoolean方法的具體用法?C# BitConverter.ToBoolean怎麽用?C# BitConverter.ToBoolean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.BitConverter
的用法示例。
在下文中一共展示了BitConverter.ToBoolean方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
class Example
{
public static void Main( )
{
// Define an array of byte values.
byte[] bytes = { 0, 1, 2, 4, 8, 16, 32, 64, 128, 255 };
Console.WriteLine("{0,5}{1,16}{2,10}\n", "index", "array element", "bool" );
// Convert each array element to a Boolean value.
for (int index = 0; index < bytes.Length; index++)
Console.WriteLine("{0,5}{1,16:X2}{2,10}", index, bytes[index],
BitConverter.ToBoolean(bytes, index));
}
}
輸出:
index array element bool 0 00 False 1 01 True 2 02 True 3 04 True 4 08 True 5 10 True 6 20 True 7 40 True 8 80 True 9 FF True
示例2: DecimalToByteArray
//引入命名空間
using System;
using System.IO;
class MainClass
{
public static byte[] DecimalToByteArray (decimal src){
using (MemoryStream stream = new MemoryStream()) {
using (BinaryWriter writer = new BinaryWriter(stream)){
writer.Write(src);
return stream.ToArray();
}
}
}
public static decimal ByteArrayToDecimal (byte[] src){
using (MemoryStream stream = new MemoryStream(src)){
using (BinaryReader reader = new BinaryReader(stream)){
return reader.ReadDecimal();
}
}
}
public static void Main()
{
byte[] b = null;
b = BitConverter.GetBytes(true);
Console.WriteLine(BitConverter.ToString(b));
Console.WriteLine(BitConverter.ToBoolean(b, 0));
b = BitConverter.GetBytes(3678);
Console.WriteLine(BitConverter.ToString(b));
Console.WriteLine(BitConverter.ToInt32(b, 0));
b = DecimalToByteArray(285998345545.563846696m);
Console.WriteLine(BitConverter.ToString(b));
Console.WriteLine(ByteArrayToDecimal(b));
}
}