

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Python Numbers
incomplete
2: Numbers Review
incomplete
3: Floor Division
incomplete
4: Exponents
incomplete
5: Changing in Place
incomplete
6: Plus Equals
incomplete
7: Scientific Notation
incomplete
8: Logical Operators
incomplete
9: Not
incomplete
10: Binary Numbers
incomplete
11: Bitwise '&' Operator
incomplete
12: Bitwise '|' Operator
incomplete
13: Damage Meter
incomplete
14: Converting Binary
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
As you may have guessed, the bitwise "or" operator is similar to the bitwise "and" operator in that it works on binary rather than boolean values. However, the bitwise "or" operator "or"s the bits together. Here's an example:
0101 is 50111 is 70101
|
0111
=
0111
Interactive example available with JavaScript enabled.
A 1 in binary is the same as True, while 0 is False. So a bitwise operation is just a bunch of logical operations that are completed in tandem. When two binary numbers are "or"ed together, the result has a 1 in any place where either of the input numbers has a 1 in that place.
| is the bitwise "or" operator in Python. 5 | 7 = 7 and 5 | 2 = 7 as well!
0101 is 50010 is 20101
|
0010
=
0111
A "guild" is a team of 2-4 players. Here are the guild-specific permissions:
can_invite – Leftmost bit (0b1000)can_kick – Second to leftmost bit (0b0100)can_enter_dungeon – Second to rightmost bit (0b0010)can_surrender – Rightmost bit (0b0001)When players are in a guild together, they gain all the permissions of all the other members of the guild!
For example, if:
can_invite permission: 0b1000can_kick permission: 0b0100Then, when they are in a guild together, they should both have the can_invite and can_kick permissions: 0b1100.
Complete the calculate_guild_perms function. It takes as input four binary numbers representing the separate permissions of each member of the guild: glorfindel, galadriel, elendil and elrond. It should return a single binary number that represents the combined permissions of all the members of the guild.
Use a series of bitwise "or" operations to calculate the union of all the member's permissions.
You can chain the "or" operator.