
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Bitwise Operators in Dart Programming
Bitwise operators are operators that are used to perform bit-level operations on operands. For example, consider two variables x and y where the values stored in them are 20 and 5 respectively.
The binary representation of both these numbers will look something like this −
x = 10100 y = 00101
We make use of all the bitwise operators in Dart to perform on the values that are shown in the above table (bit values).
In the below table all the bitwise operators that are present in Dart are mentioned.
Consider the table as a reference.
Operator | Meaning | Example | Description |
---|---|---|---|
& | Binary AND | ( x & y ) | Will produce 00100 |
| | Binary OR | ( x | y ) | Will produce 10101 |
^ | Binary XOR | ( x ^ y ) | Will produce 10001 |
~ | One's compliment | ~ x | Will produce 01011 |
<< | Left Shift | x << 2 | Will produce 1010000 |
>> | Right Shift | y >> 2 | Will produce 1 |
Let's make use of all the above mentioned bitwise operators in a dart program.
Example
Consider the example shown below −
void main(){ var x = 20, y = 5; print("x & y = ${x & y}"); print("x | y = ${x | y}"); print("x ^ y = ${x ^ y}"); print("~x = ${(~x)}"); print("x << 2 = ${x << 2}"); print("y >> 2 = ${y >> 2}"); }
Output
x & y = 4 x | y = 21 x ^ y = 17 ~x = -21 x << 2 = 80 y >> 2 = 1
Advertisements