×

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 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 Installation Guide

There are various ways of compiling and running an application created in Dart, either by compiling the Dart code to JavaScript using the Dart2js tool or by running on the...

3 minutes read.

Dart Type inference

The task of interpreting the data types of fields, methods, local variables and most generic type arguments is handled by the static analyser. However, when not enough information is provided...

5 minutes read.

Dart If statement

If statement is used to set the control on the lines of code. Using if statement, block of code is executed only if the expression in the statement returns true....

1 minute 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 Static Members

Static Members in Dart Static members are the members of the class declared using the 'static' keyword. the static members have the following characteristics :  All the objects of the class having...

3 minutes read.

Dart Booleans

Booleans Dart has a data type named ‘bool’ to represent Boolean values : true and false, which are compile-time constants. ‘True’ or ‘False’ cannot be assigned with values 1 or 0. Example, bool...

1 minute read.

Dart Enumerations

Enumeration data type in Dart In simple terms, Enumerations are referred to as named constant values. Constant values are declared as enumerations using the ‘enum’ keyword.  Implementation =  enum enum_name {    ...

2 minutes read.

Typedef in Dart

In Dart, typedef is used to generate a function type that we can use as a type annotation for declaring variables and return types of the function type. An alias...

4 minutes read.

Dart If-else-if statement

If - else - if statement enables to check the set of test expressions that evaluate to Boolean True or False, and based on this true or false the particular...

2 minutes read.

Dart Basic Program

Dart provides various convenient platforms to code and compile the program in Dart language. Some of them are: 1. Using IDE = Visual Studio code is a text editor with IDE....

3 minutes read.

Dart Basics

Dart, as earlier mentioned multiple times, is very similar to C, C++ and Java. It is an object-oriented, garbage collecting and class-based programming language. Let’s look further and see what Dart has...

10 minutes read.

Dart Sets

Sets data type in Dart A set is an unordered collection of items that are unique. Dart infers that sets tale strings as values. Example, var languages = { ‘Dart’ , ‘Flutter’, ‘Python’,...

3 minutes read.

Dart Anonymous Function

Dart functions are the user defined functions that are designed to perform specific task. The use case of the functions is that they can be directly called any number of...

3 minutes read.

Dart Miscellaneous types

Some Other Data types in Dart Apart from the data types studied so far, we have three other data types also which are as follows: NeverDynamicVoid Let us understand each one in detail, Never...

3 minutes read.

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 Loops

Looping refers to repeating or reusing the same lines of code repeatedly until a particular test condition evaluates to true. It is also known as iterating.  It is effectively used when...

4 minutes read.

Dart Recursion

Recursion is one of the most important and interesting concepts in any programming language. It can be defined as a process in which a function calls itself directly or indirectly....

5 minutes read.

Dart this Keyword

The ' this ' keyword, similar to that in Java and C#, refers to an object of the class using it. It points to the current object of the class,...

5 minutes read.

Dart Inheritance

Inheritance is a promising concept of any programming language. It is a property by which a class inherits the property of another class. Moreover, the class deriving the properties of...

5 minutes read.