2009年3月9日 星期一

入門C#--資料型別轉換

廢言
話說台論的Vocaloid
在我不知不覺時開版了耶
以後有閒情異志會去看看

﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍
這次的是相當重要的資料型別轉換
但實在簡單的誇張
只要(資料型別)就好了
所以也就......
程式碼


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int n = 10;
n = n << 1;
Console.WriteLine("n=n<<1左移一位:{0}", n);
n = n << 2;
Console.WriteLine("n=n<<2左移兩位:{0}", n);
n = n >> 2;
Console.WriteLine("n=n>>2右移兩位:{0}", n);
n>>=1;
Console.WriteLine("n>>=1右移一位:{0}", n);
Console.WriteLine();

char c1 = '9';
char c2 = '2';
char c3 = '1';
Console.WriteLine("原編碼訊息:" + c1 + c2 + c3);
int key = 11;
c1 = (char)(c1 ^ key);
c2 = (char)(c2 ^ key);
c3 = (char)(c3 ^ key);
Console.WriteLine("編碼後訊息:" + c1 + c2 + c3);

c1 = (char)(c1 ^ key);
c2 = (char)(c2 ^ key);
c3 = (char)(c3 ^ key);
Console.WriteLine("解碼後訊息:" + c1 + c2 + c3);
Console.Read();
}
}
}



附註說明!
<< >> 這些移位運算子請用2進位來看否則你看得懂有鬼
另外^不是次方!!!
這點跟VB不同請特別注意
^這是XOR運算每位元互斥運算也請用2進位看
﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍
話說這明明就是偉大的主席阿

沒有留言:

張貼留言