// // Created by Kyle Stevenson on 01/02/2025. // #ifndef BIT_OPERATIONS_H #define BIT_OPERATIONS_H #include #include #define SET_BIT(arr, x) (arr[x / 8] |= (1 << (x % 8)) /** * @brief Sets a specific bit in a byte array. * * This function sets (turns ON) the bit at index `bitIndex` * within a given byte array (`numberArray`). It ensures that * the target bit is set to `1` while leaving all other bits unchanged. * * @param numberArray Pointer to the byte array where bits are stored. * @param bitIndex The index of the bit to be set (0-based). * */ void setBit(uint8_t *numberArray, const int bitIndex); #define CLEAR_BIT(arr, x) (arr[x / 8] &= ~(1 << (x % 8))) /** * @brief Clears (sets to 0) a specific bit in a byte array. * * This function modifies the byte array (`numberArray`) by setting * the bit at `bitIndex` to `0` while keeping all other bits unchanged. * * @param numberArray Pointer to the byte array storing the bits. * @param bitIndex The index of the bit to be cleared (0-based). * */ void clearBit(uint8_t *numberArray, const int bitIndex); #define CHECK_BIT(arr, x) (arr[x / 8] & (1 << (x % 8))) /** * @brief Checks if a specific bit in a byte array is set (1) or cleared (0). * * This function checks the bit at `bitIndex` in `numberArray` and returns `true` * if the bit is set (1), and `false` if the bit is cleared (0). * * @param numberArray Pointer to the byte array storing the bits. * @param bitIndex The index of the bit to check (0-based). * @return true if the bit is set (1), false if the bit is cleared (0). * */ bool checkBit(const uint8_t *numberArray, const int bitIndex); #endif //BIT_OPERATIONS_H