int main() { // BITWISE OPERATORS = special operators used in bit level programming // (knowing binary is important for this topic) // & = AND // | = OR // ^ = XOR // > right shift int x = 6; // 6 = 00000110 int y = 12; // 12 = 00001100 int z = 0; // 0 = 00000000 z = x & y; printf("AND = %d ", z); z = x | y; printf("OR = %d ", z); z = x ^ y; printf("XOR = %d ", z); z = x > 2; printf("SHIFT RIGHT = %d ", z); return 0; }
When you promote a friend to admin in a Facebook group, you can assign them certain permissions, which control what they can do in the group. These permissions are typically represented as a series of options, each with a corresponding value, like this: Option 1: Approve posts (value: 1) Option 2: Delete posts (value: 2) Option 3: Pin posts (value: 4) Option 4: Manage members (value: 8) Permissions can be combined using a binary system. For example, if you give your friend a permission value of 5, you’re essentially giving them a combination of options 1 and 4. In binary, 5 is represented as 00000101, where the 1s correspond to the permissions you've enabled. To check if a certain permission is included, you can use the bitwise AND (&) operator. If you want to check whether they have permission for a specific option, you can perform the AND operation between the permission value and the option's value. For example, checking if option 1 (value 1) is enabled for a permission value of 5 would look like this: 5 & 1 = 1 (True, they have permission) 5 & 2 = 0 (False, they don’t have permission) 5 & 4 = 4 (True, they have permission) This way, you can easily determine which specific permissions are granted using a single number.
X is for exclusive. Think of OR as being ok with AND. 1 OR 1 = 1 1 OR 0 = 1 Because AT LEAST 1 is 1. So OR doesn't mind both being 1. 1 XOR 1 = 0 Because AT MOST should be 1. Break it into human speech and it becomes easier. True is 1 and false is 0 a XOR b = if exclusively one operand is true, return true. Else return false. AND =BOTH OR =AT LEAST 1 XOR =AT MOST 1
#include
int main()
{
// BITWISE OPERATORS = special operators used in bit level programming
// (knowing binary is important for this topic)
// & = AND
// | = OR
// ^ = XOR
// > right shift
int x = 6; // 6 = 00000110
int y = 12; // 12 = 00001100
int z = 0; // 0 = 00000000
z = x & y;
printf("AND = %d
", z);
z = x | y;
printf("OR = %d
", z);
z = x ^ y;
printf("XOR = %d
", z);
z = x > 2;
printf("SHIFT RIGHT = %d
", z);
return 0;
}
What software do you use?
@@namansalgotra6293If you are talking about where he writes the code it’s "Vs code"
where is you "Bitwise Complement Operator (~ tilde) in c" tutorial? @BroCodez
Quick Note: For Shift Left, like Bro mentioned there's a pattern.....every time you shift it, it doubles.
Ex: int x = 6;
for x
thats cool
thx man
Similarly Right Shift, x>>n = x/2^n, where 2^n is 2 raise to the power n.
This was very easy to understand and while being really descriptive, thank you so much for making that video!
you are a legend mate! Thank you for this clear explanation!
better than a course that i bought (74.99$) on udemy...
Thank you, very clear and understandable.
you know that the udemy courses have discounts right ?
Warning: just buy udemy courses when they are on sale. It happens very often (something like every other week).
I finally understood it!! I was so confused with CS50 week 4 PSET recover, now I got it, thanks!
Thank you so much very easy to understand because of your video
wonderfully explained. awesome. You are the real G.
Awesome thanks for the demo on bit wise operators, super easy to understand 👍👍👍👍
Oh so those scary looking math equations are actually just logic gates and boolean algebra lol
So bassically 12&6 is equal to 6&12 is it?
Yes
It's a logic operator; There is no left and right.
Amazing explanation. Thank you
Thank you so much! Extremely clear, amazing explanations!
this is just perfect, thanks for the explanation
Thanks for the video. Very understandable, good to get me started :)
Get truncated is the word I'm looking for. Thanks Bro Code. nice video
Excellent! Perfect explanation!
Such a good explanation
what is complex about the complement operator? it seems it just inverts 0 to 1 and 1 to 0
Thank you Bro Code. U saved me for my quiz
Thank you. I perfectly understood.
Jp Here,
Thank you :)
As someone who is in VLSI design, we do this all the time in Verilog.
thanks bro code for the helpful tips :) and to everyone have fun programming
Thanks!You made it very much easier
i finally know what this operators means, thanks.
Super helpful video! Thank you!
What kinds of uses do these commands have?
One use is : It can be really fast for calculations
@@Abon963 so, something the compiler would automatically optimize for you?
to quickly find if a number is a power of two you can do "return n>0 and n&(n-1)"
When you promote a friend to admin in a Facebook group, you can assign them certain permissions, which control what they can do in the group. These permissions are typically represented as a series of options, each with a corresponding value, like this:
Option 1: Approve posts (value: 1)
Option 2: Delete posts (value: 2)
Option 3: Pin posts (value: 4)
Option 4: Manage members (value: 8)
Permissions can be combined using a binary system. For example, if you give your friend a permission value of 5, you’re essentially giving them a combination of options 1 and 4. In binary, 5 is represented as 00000101, where the 1s correspond to the permissions you've enabled.
To check if a certain permission is included, you can use the bitwise AND (&) operator. If you want to check whether they have permission for a specific option, you can perform the AND operation between the permission value and the option's value. For example, checking if option 1 (value 1) is enabled for a permission value of 5 would look like this:
5 & 1 = 1 (True, they have permission)
5 & 2 = 0 (False, they don’t have permission)
5 & 4 = 4 (True, they have permission)
This way, you can easily determine which specific permissions are granted using a single number.
Bro!!!!! You are awesome and thank you
I'm grateful that I didn't skip binary in high school math class.
Thank you for this
thx and great style
Masterpiece❤
Your a real programmer 😎
Ok cool thanks my reference book did not explain shifts very well.
Thanks bro
BIG LIKE!
Thanks man
Thank you so much :)
Perfect!
Thank you!
where is ~ (complement operator)
thanks man
bro code the goat.
thx buddy
Thank you
Thanks.
TYSM
King!
huge respect
شكرا
Simple yet easy to understand
1:25
giga big coc chad thx
bruh
for xor , 1 OR 1 = 1: If both bits are 1, the result is , how come 1 and 1 is zero
X is for exclusive. Think of OR as being ok with AND.
1 OR 1 = 1
1 OR 0 = 1
Because AT LEAST 1 is 1. So OR doesn't mind both being 1.
1 XOR 1 = 0 Because AT MOST should be 1. Break it into human speech and it becomes easier.
True is 1 and false is 0
a XOR b = if exclusively one operand is true, return true. Else return false.
AND =BOTH
OR =AT LEAST 1
XOR =AT MOST 1
Ty :)
legend.
Why do you use %d ?
It is an format specifier it this time you know what is that....I hope you know😅😅😅😅
Is it just me who noticed the text size change as the first change?
yeah i completely forgot it
Hello
Robert
try 100
Thanks bro
Thanks bro