← DiffPush

Bitwise Basic Operations

Baseline Tries · Problems O(1) · O(1)

The Signal Gate Bench Test

A hardware lab certifies three micro-operations on its logic probe: a difference-flip between two signal words (XOR), a read of one bit position, and a write that switches a bit on. Each probe routine runs in constant time and is exercised with concrete word values before sign-off.

Input: Integers a, b for the XOR test; c (bit index), d (word) for the read test; e (bit index), f (word) for the write test.

Output: Return a triple: a XOR b; then 1 if bit c of d is set else 0; then f with bit e forced on.

Constraints

Examples

Example 1

Input: {"a":5,"b":3,"c":1,"d":6,"e":0,"f":8}
Output: [6,1,9]
5^3 = 6; bit 1 of 6 (110) is 1; 8 with bit 0 set becomes 9.

Example 2

Input: {"a":12,"b":10,"c":0,"d":4,"e":1,"f":4}
Output: [6,0,6]
12^10 = 6 (1100 vs 1010 differ in two bits); bit 0 of 4 is unset; forcing bit 1 on gives 4 | 2 = 6.

Solve this in your browser →

Also on LeetCode ↗