53. Modify Bytes in a 32-bit Value Using Union

You are given a 32-bit integer.

You must:

  1. Use a union to access and modify its individual bytes
  2. Modify the 2nd and 3rd bytes (i.e., bytes[1] and bytes[2]) with new values
  3. Reconstruct and print the modified 32-bit value

Only use union-based access. Do not use bitwise operations or shifts.


Example-1

Input: 
value = 305419896 (0x12345678)
new_b1 = 0xAA, new_b2 = 0xBB
Output: 314288760

(0x12BBAA78 → bytes = [0x78, 0xAA, 0xBB, 0x12])


Example-2

Input: 
value = 1
new_b1 = 255, new_b2 = 255
Output: 16776961

(0x00FFFF01)


Example-3

Input: 
value = 0
new_b1 = 1, new_b2 = 2
Output: 131328

(0x00020100)


 

Loading...

Input

305419896 170 187

Expected Output

314288760