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\n, c ); 

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

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

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

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

   c = a >> 2;     /* 15 = 0000 1111 */ 
   writefln(Line 6 - Value of c is %d\n, c );

   return 0; 
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


// ------------------- import std.stdio; void main(string[] args) { writeln("Hello World!");
import std.stdio; int main () { /* local variable definition */ int a = 10; /* while loop execution */
import std.stdio; int main(string[] args) { int a = 20; int b = 10; int c = 15; int d = 5; int e; e = (a + b) * c / d;// ( 30 * 15 ) / 5
import std.stdio; int main(string[] args) { int a = 4; short b; double c; int* ptr; /* example of sizeof operator */
import std.stdio; int main(string[] args) { int a = 21; int c ; c =a; writefln("Line 1 - =Operator Example, Value of c = %d\\n", c );
import std.stdio; int main(string[] args) { uint a = 60; /* 60 = 0011 1100 */ uint b = 13; /* 13 = 0000 1101 */
import std.stdio; int main(string[] args) { int a = 5; int b = 20; int c ; if ( a && b ) { writefln("Line 1 - Condition is true\\n" );
import std.stdio; int main(string[] args) { int a = 21; int b = 10; int c ; if( a == b ) { writefln("Line 1 - a is equal to b\\n" );
import std.stdio; int main(string[] args) { int a = 21; int b = 10; int c ; c = a + b; writefln("Line 1 - Value of c is %d\\n", c );
import std.stdio; int main(string[] args) { writefln("Hello\\tWorld%c\\n",'\\x21');
import std.stdio; enum { A = 1.2f,// A is 1.2f of type float B,// B is 2.2f of type float int C = 3, // C is 3 of type int
import std.stdio; enum : string { A = "hello", B = "world", } int main(string[] args) {
import std.stdio; // Initialized sun with value 1 enum { sun , mon, tue, wed, thu, fri, sat }; int main(string[] args) {
import std.stdio; // Initialized sun with value 1 enum Days { sun = 1, mon, tue, wed, thu, fri, sat };
import std.stdio; enum Days { sun, mon, tue, wed, thu, fri, sat }; int main(string[] args) { Days day; day = Days.mon;
import std.stdio; int main() { writeln("Length in bytes: ", char.sizeof); return 0; }
import std.stdio; int main() { writeln("Length in bytes: ", float.sizeof); return 0; }
// --------------------- import std.stdio; int main() { writeln("Length in bytes: ", ulong.sizeof);
import std.stdio; int a = 10, b = 10; int c; float f; int main () { writeln("Value of a is : ", a);
import std.stdio; void main(string[] args) { char[9] greeting1 = "Hello all"; writefln("%s",greeting1);