本文整理汇总了C#中Binary.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Binary.ToString方法的具体用法?C# Binary.ToString怎么用?C# Binary.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Binary
的用法示例。
在下文中一共展示了Binary.ToString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertBinaryToItemId
private string ConvertBinaryToItemId(Binary binary)
{
byte[] binaryString = binary.ToArray();
// if the original encoding was ASCII
string x = Encoding.ASCII.GetString(binaryString);
// if the original encoding was UTF-8
string y = Encoding.UTF8.GetString(binaryString);
// if the original encoding was UTF-16
string z = Encoding.Unicode.GetString(binaryString);
string strBinary = binary.ToString();
StringBuilder result = new StringBuilder(strBinary.Length / 8 + 1);
// TODO: check all 1's or 0's... Will throw otherwise
int mod4Len = binary.Length % 8;
if (mod4Len != 0)
{
// pad to length multiple of 8
strBinary = strBinary.PadLeft(((strBinary.Length / 8) + 1) * 8, '0');
}
for (int i = 0; i < binary.Length; i += 8)
{
string eightBits = strBinary.Substring(i, 8);
result.AppendFormat("{0:X2}", System.Convert.ToByte(eightBits, 2));
}
return result.ToString();
}
示例2: Print
private void Print(Binary value, UInt16 index)
{
Console.WriteLine(_scadaDev.Name + ": Binary[" + index + "] " + value.ToString());
}
示例3: ToString
public new void ToString()
{
byte[] data = new byte[] { 0x1, 0x2, 0x3, 0x4 };
Binary b = new Binary(data);
Assert.AreEqual('"' + Convert.ToBase64String(data) + '"', b.ToString());
}
示例4: DisplayRawHexValues
public void DisplayRawHexValues()
{
var bytes = new Binary(new Byte[] { 1, 2, 3, 4 });
Assert.Equal("0x01020304", bytes.ToString());
}