Bitwise Operators in C (Part 4)

preview_player
Показать описание
C Programming & Data Structures: Bitwise Operators in C (Part 4)
Topics discussed:
1. Bitwise XOR Operator.
2. Difference between Inclusive OR and Exclusive OR.
3. Example of Bitwise XOR Operator.
4. Homework problem.

Music:
Axol x Alex Skrindo - You [NCS Release]

#CProgrammingByNeso #CProgramming #BitwiseOperators
Рекомендации по теме
Комментарии
Автор

a = a ^ b = 4 ^ 3 = 7;
b = a ^ b = 7 ^ 3 = 4;
a = a ^ b = 7 ^ 4 = 3;
Output:- After XOR, a = 3 and b = 4

nikhiljain
Автор

This program is the swapping of two number program
a=a^b=4^3=7
b=a^b=7^3=4
a=a^b=7^4=3
Therefore the output is:
After XOR a=3 and b=4

nishaagarwal
Автор

a=3 and b=4 so XOR bitwise operators can be used in swapping variables

roaahedaya
Автор

1. a=a^b //7
2. b=a^b //4<--final b
3. a=a^b //3<--final a
Final output --> After XOR, a=3 and b=4

karriprakash
Автор

Honestly the best tutorial I found on YouTube is without doubt The Neso Academy 👍

rachanapurohith
Автор

Yaar litreally, i was hell confused in all these operators and there working, but i had founded this playlist of neso and c programming of geeksforgeeks and i am hell addicted now .
I just solve questions in the lockdown .
My college professor sucks in programming and i was thinking that i was too dumb in understanding all these concepts .
Thanks neso :)

harshmk
Автор

a = 3 and b = 4
(Concept:swapping of two variables without using third variable using XOR bitwise operator);

MRHL
Автор

The values of variables are swapped. The reason behind it is as mentioned below..
The magic of xor:
Suppose you have two variables a and b, then if you perform xor between them you will get the third variable, suppose it as c.
Now you will be amazed by the fact that performing xor between any two variables you will get the third one. So, if you perform xor between a and c you will get b, xor between b and c will give you a and so on . Thus, this property helps in swapping two variables easily.

nabinbhusal
Автор

the best playlist for understanding ever existed.

adithya_galipelli
Автор

Swapping using logical operator
1st statement a=a^ b; here 7 got stored in a
2nd statement b=a^ b; by using a= 7 and b= 3 , 4 will get stored in b
After that a= a^b; using a=7, b=4, value of a will be 3.

kusumrana
Автор

So for ya'll that don't know the method presented in the homework part, it is called magic swap. It always works but don't bother, it takes more cpu clocks than the usual #asm xchg and it is also slightly less inefficient than swap. It is good to know about it if you get a question at an interview tho.

Gabriel
Автор

AFTER FIRST XOR the value of "a" changes to 7, and second XOR value of "b" changes to 4, and after third XOR value of "a" change to 3 so final output will be After XOR, a=3, b=4

gauravrajpurohit
Автор

You should be teching at an NIT or IIT.... You are really good at teaching. You make it simple for us to understand.

kartikenbarnwal
Автор

Bitwise XOR Operator of the above program is a=a^b; 4^3=7
b=a^b;7^3=4
a=a^b;7^4=3
So a=3 and b=4 ☺️

ponnadamahesh
Автор

it swaps the value of the variables; amazing operator!

bikashthakur
Автор

You can use this if question asks you to swap values without using " Third variable(TEMP)"

anupamparihar
Автор

a=a^b; 4^3=7=a
b=a^b; 7^3=4=b
a=7; b=4 then a=a^b; 7^4=3
Output:After XOR, a=3 and b=4

badavathjaipal
Автор

I don't know what to to Dear Neso Volunteers This is what I was looking for .

mbwanaibrahim
Автор

this playlist is so addicting ...like web series...I m in love with programming after watching neso academy's lectures of C

nikita_khot
Автор

a = 3
b = 4
Thank you @Neso Academy, I love how detailed your explanation is.

chinua