003-005-004

Bitwise Operations: Basics of Flag Management

Medium

Problem Description

Flag Management with Bitwise Operations

Bitwise operations efficiently manage multiple ON/OFF flags in a single integer.

Basic Operations

// Set bit (make it 1)
Flags |= (1 << position);

// Clear bit (make it 0)
Flags &= ~(1 << position);

// Check bit
Boolean isSet = (flags & (1 << position)) != 0;

Learning Points

  • | (OR): Set bits
  • & (AND): Check bits, combine with ~ to clear
  • << (left shift): Move 1 to specified position
  • Used in practice for permission management etc.
.

Test Cases

※ Output examples follow programming industry standards

Input:
5
SET
1
Expected Output:
7
Input:
7
CLEAR
2
Expected Output:
3
Input:
10
CHECK
1
Expected Output:
ON
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here

sc.close();
}
}
0 B / 5 MB

You have 10 free executions remaining