×

Dart Bitwise and Shift Operators

The Bitwise operators are the operators that perform different operations bit by bit on the value of the two operands.

List of Bitwise Operators in Dart

Sr.

Operators

Description

1.

& ( Binary AND )

It returns 1 if and only if both bits are 1, and returns 0 if either one of them is 0.

2.

| ( Binary OR )

It returns 1 if any of the bits is 1, and returns 0 if and only if both bits are 0.

3.

^ ( Binary XOR )

It returns 1 if both bits are different, and returns 0 if both bits are same.

4.

~ ( 1’s Complement )

It returns the reverse of the bit. If the bit is 0 then the complement will be 1.

5.

<< ( Shift left )

The value of the left operand shifts to the left by the number of bits present in the right of the operator.

6.

>> ( Shift right )

The value of the right operand shifts to the right by the number of bits present in the left of the operator.


Program

void main( )

{

  print( " Bitwise Operators \n " ) ;

  var a  = 50 ;

  var b = 40 ;

  var c = 0 ;

  // Bitwise AND Operator

  var res1 = a & b ;

  print( " a & b = " ) ;

  print( res1 ) ;

  // Bitwise OR Operator

  var res2 = a | b ;

  print( " \n a | b = " ) ;

  print( res2 ) ;

  // Bitwise XOR

  var res3 = a ^ b ;

  print( " \n a ^ b =  " ) ;

  print( res3 ) ;

  // Complement Operator

  var res4 = ~a ;

  print( " \n ~a = " ) ;

  print( res4 ) ;

  // Binary left shift Operator

  var res5 = a << 2 ;

  print( " \n c << 1 = " ) ;

  print( res5 ) ;

  // Binary right shift Operator

  var res6 = a >> 2 ;

  print( " \n c >> 1 = " ) ;

  print( res6 ) ;

}

Output

 Bitwise Operators

a & b =

32

a | b =

58

a ^ b =

26

~a =

4294967245

c << 1 =

200

c >> 1 =

12

Related Topics

Dart Logical Operators

Logical operators are the operators that combine two or more conditions, and accordingly return a Boolean value : true or false. Assume the value of variable A is 25 and B...

2 minutes read.

Dart Tutorial

Dart is an open-source, structured programming language developed by Google. It is a high-level programming language that emerged in 2011, but its stable version emerged in 2017. It is largely used...

4 minutes read.

main function in Dart

The main( ) function is a predefined method in Dart that is also known as the entry-point of the program. The compiler begins the execution only when it comes across...

3 minutes read.

Dart Generators

Synchronous Generator Dart Generator is a unique function that allows us to generate price sequences. Generators return values when needed; means that the value is generated if we try to duplicate...

5 minutes read.

Dart Arithmetic Operators

Arithmetic Operators comprises of all the operators that are used to perform arithmetic operations such as addition, subtraction, multiplication, division, etc. They are binary operators that work upon two operands. Consider A...

2 minutes read.

Dart Optional Parameters

Dart functions can have optional parameters with default values. When we create a function, we can specify parameters that calling code can provide; but if the calling code chooses not...

2 minutes read.

Dart Built-in Data Types

A data type defines the type of value a variable can hold, such as integer, double, or string.  Dart supports two data types:  1. Built-in data types : These are the data...

1 minute read.

Dart Symbols

Symbols data type in Dart A symbol is an object that is the representation of an operator or identifier in Dart. These are compile-time constants.  They are used in APIs that refer...

1 minute read.

Dart Iterable

Iterable is a collection of elements that are accessed sequentially. These elements are accessible using the iterator getter and stepping through the values using this getter. Let us understand the setting...

6 minutes read.

Dart super keyword

The ' super ' keyword is used to refer to the immediate parent class object of the currently in-use child class. Using this keyword, we can invoke the superclass (...

6 minutes read.

Dart Method Overriding

Before understanding method overriding, it is important to clear the concept of polymorphism. Polymorphism is derived from two Greek words 'Poly' which means many and 'morphs' which means many forms....

5 minutes read.

Dart Runes and Graphemes

Runes and Graphemes data types in Dart Runes and Graphemes Runes are the special string of Unicode UTF-32 bits that represent the special syntax. Unicode defines a unique numeric value for each...

2 minutes read.

Dart Classes

Dart is an object – oriented programming language that supports all the object-oriented programming concepts such as classes, objects, inheritance, data abstraction and data encapsulation. A class can be defined as...

8 minutes read.

Unit Testing in Dart

Typing testing ensures that your app keeps working as you add more features or change existing functionality. Unit testing helps to confirm the behavior of a single function, method, or...

4 minutes read.

Dart Comments

Comments are the statements that are used to enhance the readability and understandability of the code. The compiler does not execute these lines. It simply ignores these comments when it scans...

2 minutes read.

Soundness in Dart

What is soundness? Soundness ensures that the program never comes across any invalid state that may lead to abrupt termination of the program. As its name suggests it ensures perfect type...

4 minutes read.

C++ vs Dart

Difference between C++ and Dart C++ is an object-oriented programming language developed in 1980 by Bjarne Stroustrup. It has wide real-world applications with various in-built functions and a very vast library...

1 minute read.

Dart HTML DOM

All web pages can be viewed as objects and exist within the browser window. We can access a web page using a web browser and it needs to be connected...

3 minutes read.

Dart Construtors

Constructors are the very important concept in any programming language. They are the special functions created in the classes to allocate memory to the objects of that class when created...

4 minutes read.

Dart Packages

Every programming language has some in-built functions stored inside the header files that makes the task much easier for the programmer. The Dart Packages refer to the compilation of a...

4 minutes read.