Bit Manipulation Basics
Content
Decimal Number System
Binary Number System
Binary to Decimal conversion
Decimal to Binary conversion
Addition of Decimal Numbers
Addition of Binary Numbers
Bitwise Operators
ve No Binary Representation 2 s compliment
Range of Datatypes
Importance of constraints
69.5 75 80
Average PSD
better
more PSP confidence contest
performance
If you are stuck at a problem max time 25 mins
Hint 1 Hintz Video solution
TA video call Help request
Post in WA group
reach out to me
Decimal Number System
34120 300 40 2 34102 4 10 t
2 100
3526130 2 103 5 102 6 10 t 3 100
Binary Number System false
true
digits yo
it 8 1 22 1 2 t 0 20
set
u 2 0 g son
3 2 10 Ynet
1 0 I 1 1 23 0 22 1 2 t 1 20
8 to 2 I 11
Binary to Decimal conversion
convert 1101 to decimal
311289 23 22 20 8 U t 1 13
Convert 10101 to decimal
48489 24 22 20 16 4 t 1
21
I 84 8 I 8 26 24 23 2
GU t 16 8 2
9L
Decimal to Binary conversion
convert 20 to binary
num remainder
2 on
2 10 0 Bottom to top
2 I I 48188
2 2 O
24 22 16 4 20
2 I 1
2 90 O n
2 45 1
2 22 0 10 110 10
2 11 I
2 T t
2 2 O
2 I 1
O
2 45 I n
2 22 O
2 11 1 10 1101
2 5 I
2 2 O
2 I I
0
Addition of Decimal Numbers
3 É 8
4 5 3
82 I
Addition of Binary Numbers
1 1 2 10
decimal Binary
1
id d 1 21 t t t I 0 1 53
I 1 0 1 13 I 0 0 1 I 0 38
180018 34 to II o'I I g
25 21 32 2 26 24423 21 20
31
Gut 16 8 2 1
GI
ti
t I I 1 1 1 3 11
1 10
18110
00 I 1 I
11101
Bitwise Operators Addition without carry
Binary operator AND OR XOR
A B A B A B AN B
O O O O O
O I 0 I 1
I 0 0 I 1
I I 1 I 0
It all It s t
u
else o
If any I I
else O
same same
zero game
Unary operator
NOT
A A
0 I
1 O
Examples
5 6 5 10 1 5 86 4
6 1 10
10 O U
20 8 45 20 0 0 I 00
45 10 1 10 I
000 100 7 4
20 UF 20 0 0 I 00
45 10 1 10 1
II I I'O É
25 24 23 22 20
32 1648 4 1
GI
92 A 154
92 010 1 11 00
154 N I 0011 0 I 0
110001 I O
92
92 10 1 11 O O
92 01000 1 1
20 0 0 I 00
A 45 10 1 10 1
I 1 1 00 I
Binary Representation of ve
very first bit acts as the signed bit
int U bytes 32 bits
signed
9 feigtifive
For simplicity we will assume only 8 bits
5 in 8 bit representation
Steps for 25 compliment
Ignore the sign and write binary repre
O O 0 0 0 1 0 I
N N
I I 1 I 1 0 I 0 IS compl ment
I
F G T 4 3 2 I 0
I 1 I 1 I 0 I 1
27 36 2 34 13 1 50
128 64 32 16 8 2 1 Is
compliment
I
NOTE 2s compliment is how the ve no H
stored
Binary rep of absolute value say N
N
I
Q 3 in 8 bit representation
step 1 O O O O 0 0 1 I
step 2 I 1 I 1 I 1 0 O
steps I i 5 i i o I
Y
27 26 25 24 23 22 20
128 64 32 76 8 tu t 1
80 40 5
128 125 3
10 in 8 bit representation
step 1 O O O O 1 0 I 0
step 2 1 I 1 I 0 I 0 1
steps I E I 81 8
27 26 25 24 22 21
128 6443 2 16 4 2
128 80 37
128 118 I
Break 22 50
Range of Datatypes
bits min max Range
2 I 0 O T2 I
2 0 2 y
3 I QQ old T 4,3
22 y
u too T 8,77
23 8 Itt
I 868 I 5 128.127
8
II it
2642724 23 2421 20
27 I
32 231 231 1 2 109
2 109
2 109 5 109
GU 263 263 I
210 1024 1000
6 1018
210 210 2 10 210 210 210 03
1018
8
Range 8 1018 to 8 1018
Importance of constraints
int a 105 int range 2 709 to 2 109
int b 106
int c a b
10 s overflow of integer
long c a b t operation a
poll in taint int
The result will be int
This result will be stored in C
long c long a b
long int long
10 11 correct value
steps s a will be typecarted to long
long int b
a k
temp result will be stored as long
C is assigned temp result
Constraints S N 51 to 105
Ali I I I to 100 cannot be
int sum 0 stored in int
for i s o to N t
sum Ati Ati 7 106
3 105 106 1010
print sum 11 garbage value
long sum 0
for i s o to N t
sum Ati
3
print sum 11 right value
No confusion code
long sum 0
for i s o to N t
3
[Link]
print sum 11 right value
HW Take simple code examples and print the
results
Doubt session
109 7
result i Mop
O Xi 15 15
oracle idk if Array list
Array support inte
How to solve problem
Read the question
Understand input output
Bruteforce
your code should give right
result on simple tests
optimise
Exceeded 25min on a question
Hint I
Hint 2
Video Sol
TA video call
I Whatsapp
Text me