在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ C++/ D語言位運算符
類的訪問修飾符
D語言運算符
D語言邏輯運算符
類指針
D語言元組
D語言指針
D語言模塊
D語言sizeof運算符
D語言混合類型
D語言封裝
D語言條件編譯
類的靜態(tài)成員
D語言do...while循環(huán)
D語言結(jié)構(gòu)體
重載
D語言字符串-String
D語言決策語句
D語言接口
D語言for循環(huán)
D語言switch語句
D語言關(guān)聯(lián)數(shù)組
D語言范圍
D語言枚舉Enums
契約式編程
D語言并發(fā)
D語言開發(fā)環(huán)境設(shè)置
D語言別名
D語言常值
D語言常量
D語言函數(shù)
D語言if嵌套語句
D語言循環(huán)
D語言概述,D語言是什么?
D語言運算符優(yōu)先級
D語言continue語句
D語言異常處理
D語言break語句
D語言if...else語句
D語言類和對象
類繼承
D語言字符
D語言教程
D語言關(guān)系運算符
比較操作符重載
構(gòu)造函數(shù)和析構(gòu)函數(shù)
D語言抽象類
D語言if語句
D語言賦值運算符
D中算術(shù)運算符
D語言類成員函數(shù)
D語言位運算符
D語言變量
D語言數(shù)據(jù)類型
D語言文件I/O
D語言數(shù)組
一元運算符重載
D語言嵌套switch語句
D語言基本語法
二元運算符重載
this指針
D語言聯(lián)合體
D語言模板
D語言嵌套循環(huán)
D語言while循環(huán)

D語言位運算符

由D語言支持的位運算符列于下表中。假設(shè)變量A=60和變量B=13,則:

運算符 描述 示例
& 二進制AND拷貝操作,如果它存在于兩個操作數(shù)的結(jié)果。 (A & B) will give 12 which is 0000 1100
| 二進制OR運算符拷貝位,如果它存在一個操作數(shù)中。 (A | B) will give 61 which is 0011 1101
^ 二進位異或運算符拷貝位,如果它被設(shè)置在一個操作數(shù),但不能同時使用。 (A ^ B) will give 49 which is 0011 0001
~ 二進制的補碼運算符是一元的,具有'翻轉(zhuǎn)'位的效果。 (~A ) will give -61 which is 1100 0011 in 2's complement form due to a signed binary number.
<< 二進制左移位運算符。左操作數(shù)的值被移動由右操作數(shù)指定的位數(shù)。 A << 2 will give 240 which is 1111 0000
>> 二進制右移運算。左操作數(shù)的值是正確的由右操作數(shù)指定的位數(shù)移動。 A >> 2 will give 15 which is 0000 1111

示例

試試下面的例子就明白了所有的D編程語言位運算符:

import std.stdio;

int main(string[] args)
{

   uint a = 60;	/* 60 = 0011 1100 */  
   uint b = 13;	/* 13 = 0000 1101 */
   int c = 0;           

   c = a & b;       /* 12 = 0000 1100 */ 
   writefln("Line 1 - Value of c is %d
", c );

   c = a | b;       /* 61 = 0011 1101 */
   writefln("Line 2 - Value of c is %d
", c );

   c = a ^ b;       /* 49 = 0011 0001 */
   writefln("Line 3 - Value of c is %d
", c );

   c = ~a;          /*-61 = 1100 0011 */
   writefln("Line 4 - Value of c is %d
", c );

   c = a << 2;     /* 240 = 1111 0000 */
   writefln("Line 5 - Value of c is %d
", c );

   c = a >> 2;     /* 15 = 0000 1111 */
   writefln("Line 6 - Value of c is %d
", c );
   return 0;
}

當編譯并執(zhí)行上面的程序它會產(chǎn)生以下結(jié)果:

Line 1 - Value of c is 12

Line 2 - Value of c is 61

Line 3 - Value of c is 49

Line 4 - Value of c is -61

Line 5 - Value of c is 240

Line 6 - Value of c is 15