日期:2014-05-17 浏览次数:20420 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s1 = "骞垮窞";
string s2 = "广州";
byte[] b1 = Encoding.UTF8.GetBytes(s1);
byte[] b2 = Encoding.UTF8.GetBytes(s2);
ShowBytes(b1);
Console.WriteLine();
ShowBytes(b2);
}
static void ShowBytes(byte[] data)
{
Console.WriteLine(string.Join(" ", data.SelectMany(x => new int[] { x / 16, x % 16 }).Select(x => Convert.ToString(x, 2).PadLeft(4, '0'))));
Console.WriteLine(string.Join(" ", data.Select(x => Convert.ToString(x, 2).PadLeft(8, '0'))));
Console.WriteLine(string.Join(" ", data.Select(x => Convert.ToString(x, 16).ToUpper().PadLeft(2, '0'))));
}
}
}
1110 1001 1010 1010 1001 1110 1110 0101 1001 1110 1010 1110 1110 0111 1010 1010
1001 1110
11101001 10101010 10011110 11100101 10011110 10101110 11100111 10101010 10011110
E9 AA 9E E5 9E AE E7 AA 9E
1110 0101 1011 1001 1011 1111 1110 0101 1011 0111 1001 1110
11100101 10111001 10111111 11100101 10110111 10011110
E5 B9 BF E5 B7 9E
Press any key to continue . . .