0% found this document useful (0 votes)
14 views

Bitwise

The document discusses different bitwise operators like AND, OR, NOT, XOR and shift operators like left and right shift. It provides examples of each operator being used on sample bit values and shows the step-by-step workings. Common uses of each operator are also demonstrated.

Uploaded by

Aman Yadav 7-E
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Bitwise

The document discusses different bitwise operators like AND, OR, NOT, XOR and shift operators like left and right shift. It provides examples of each operator being used on sample bit values and shows the step-by-step workings. Common uses of each operator are also demonstrated.

Uploaded by

Aman Yadav 7-E
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

## Bitwise (&, |, ~, ^, <<, >>)

a=10 ## => 1010

b=4 ## => 0100

print('A : {}, B : {}'.format(a,b))

#AND (&) operator

print("a & b = ",a&b)

#Output : 0

#OR (|) operator

print("a | b = ",a|b)

###Output : 14

###Complement/Not (~)

print("~a = ",~a)

###Output : -11

###XOR (^)

print("a ^ b = ",a^b)

###Output : 14

##### 0101 1010

####^ 0111 0100

####------------------

#### 0010(2) 1110(14)

##

###Right Shift (>>) operation


print("a >> 2 = ", a>>2)

###Output 2

### a >> 2 => 1010 >> 2 => 0010 => 2

### 5 >> 2 => 0101 >> 2 => 0001 => 1

### 5 >> 3 => 0101 >> 3 =>> 0000 => 0

### a >> 2 => 10 >> 2 => 10/(2^2) => 10/4 => 2

### 5 >> 2 => 5 /(2^2) => 5/4 = 1

### 5 >> 3 => 5 /(2^2^2) => 5/8

##

##

###Left Shift (<<) operation

##print("a << 2 = ",a<<2) # 10 << 2 => 1010 << 2 => 101000 => 40

###Output 40

##

### 10 << 2 => 10 * (2^2) => 10 * 4 => 40

##

##print("5 << 2 = ",5<<2)

### 5 *(2^2)= 5 * 4 => 20

### 5 << 2 => 0101 << 2 => 010100 => 20

##print("5 << 3 = ",5<<3)

### 5 << 3 => 0101 << 3 => 0101000 => 40

### 5 *(2^2^2)= 5*8 => 40

##print("10 << 3 = ",10<<3)

You might also like