Dart 编程 - 位运算符


例子

以下示例展示了如何在 Dart 中使用按位运算符 -

void main() { 
   var a = 2;  // Bit presentation 10 
   var b = 3;  // Bit presentation 11 
   
   var result = (a & b); 
   print("(a & b) => ${result}");    
   result = (a | b); 
   print("(a | b) => ${result}");
   result = (a ^ b); 
   print("(a ^ b) => ${result}"); 
   
   result = (~b); 
   print("(~b) => ${result}");  
   
   result = (a < b); 
   print("(a < b) => ${result}"); 
   
   result = (a > b); 
   print("(a > b) => ${result}"); 
}  

它将产生以下输出-

(a & b) => 2
(a | b) => 3 
(a ^ b) => 1           
(~b) => -4             
(a < b) => true                             
(a > b) => false
dart_programming_operators.htm