

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
No active XP Potion
Accept a Quest
Login to submit answers
Back
ctrl+,
Next
ctrl+.
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
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 partied 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 superset of all the member's permissions.
You can chain the "or" operator.
Focus Editor
Alt+Shift+]
Next Tab
Alt+Shift+[
Become a member to Submit
Become a member to Run
Become a member to view solution