Chapter 17 : Bitwise Operators

Topics Covered :

1. What are Bitwise Operators
2. & : (Bitwise AND)
3. | : (Bitwise OR)
4. ^ : (Bitwise EXCLUSIVE OR)
5. ~ : (Bitwise NOT)
6. << : (Bitwise Shift left)
7. >> : (Bitwise Shift right)
8. Examples

# Bitwise Operators

In Swift Programming we can perform operations of bits (binary 0s and 1s) using Bitwise operators.

1. & : (Bitwise AND)

2. | : (Bitwise OR)

3. ^ : (Bitwise EXCLUSIVE OR)

4. ~ : (Bitwise NOT)

5. << : (Bitwise Shift left)

6. >> : (Bitwise Shift right)

#### Bitwise AND (&)

``````
//
//  main.swift
//  Swift Tutorials 2014-15
//  Bitwise AND (&) Operator in Swift
//
//  Created by Code2care on 16/09/14.
//

var a = 3;  //binary 11
var b = 2;  //binary 10

println(a & b) // 11 AND 10 = 10 (decimal 2)

```
```
Output :

2
Program ended with exit code: 0

#### Bitwise OR (|)

``````
//
//  main.swift
//  Swift Tutorials 2014-15
//  Bitwise OR (|) Operator in Swift
//
//  Created by Code2care on 16/09/14.
//

var a = 3;  //binary 11
var b = 2;  //binary 10

println(a | b) // 11 OR 10 = 11 (decimal 3)

```
```
Output :

3
Program ended with exit code: 0

#### Exclusive OR (^)

``````
//
//  main.swift
//  Swift Tutorials 2014-15
//  Bitwise OR (|) Operator in Swift
//
//  Created by Code2care on 16/09/14.
//

var a = 3;  //binary 11
var b = 2;  //binary 10

println(a ^ b) // 11 OR 10 = 1 (decimal 1)

```
```
Output :

1
Program ended with exit code: 0