003-005-003

Bitwise Operators: Permission Flag Management

Medium

Problem Description

Bitwise Operators: Permission Flag Management

In this problem, you will create a program that checks whether a given permission flag is set in the current permission value using the bitwise AND operator (&) and displays the result to standard output.

Learning Objective: Set and check flags using bitwise operators (&, |, ^)

Create a user permission system. Use bitwise operators to manage read, write, and execute permissions.

Permission Flags

  • READ = 1 (binary: 001)
  • WRITE = 2 (binary: 010)
  • EXECUTE = 4 (binary: 100)

Input

Line 1: Current permission value (integer 0-7)
Line 2: Permission to check (1=READ, 2=WRITE, 4=EXECUTE)

Output

Permission: [current permission]
[permission name]: [yes/no]

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up