ASCII碼與Unicode碼的區別
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AsciiText { class Program { static void Main(string[] args) { //默認的是 unicode編碼 String str = "I live in 中國!"; //Unicode Encoding uni_str = Encoding.Unicode; //獲取Unicode編碼 byte[] uni_byte = uni_str.GetBytes(str); Console.WriteLine("Unocode:"); for(int i=1;i{0}", uni_str.GetString(uni_byte)); //ASCII 編碼 Encoding ascii_str = Encoding.ASCII; //獲取ACSII編碼 byte[] ascii_byte = ascii_str.GetBytes(str); Console.Write("ASCII:"); for(int i=0;i{0}", ascii_str.GetString(ascii_byte)); Console.ReadLine(); } } }
結果輸出:
Unocode:
0-32-0-108-0-105-0-118-0-101-0-32-0-105-0-110-0-32-0-45-78-253-86
n 中國!
ASCII:73-32-108-105-118-101-32-105-110-32-63-63-33->I live in ??!
1.
byte [] intBuff = BitConverter.GetBytes(i); // 將 int 轉換成字節數組
2.
byte [] doubleBuff = BitConverter.GetBytes(x); // 將 double 轉換成字節數組
3.
lob.Write(doubleBuff, 0, 8);
x = BitConverter.ToDouble(doubleBuff, 0); // 從字節數組轉換成 double
4.
lob.Write(intBuff, 0, 4);
i = BitConverter.ToInt32(intBuff, 0); // 從字節數組轉換成 int
using System;
class test2
{
static void Main()
{
for(int i=1;i<=255;i++)
{
if (i % 10 == 0)
Console.Write("{0}\n", (char)i);
else
Console.Write("{0}", (char)i);
}
Console.ReadLine();
}
}