本文整理匯總了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());
}