#include <stdio.h> #include <stdint.h> uint8_t set_range(uint8_t reg, uint8_t start, uint8_t end) { // Ensure start <= end if (start > end || start > 7 || end > 7) { return reg; // Invalid input, return unchanged } for (uint8_t i = start; i <= end; i++) { reg |= (1 << i); } return reg; } int main() { uint8_t reg, pos; scanf("%hhu %hhu", ®, &pos); uint8_t result = toggle_bit(reg, pos); printf("%u", result); return 0; }
Test Cases
Test Results
Input
6 1
Expected Output
4