-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
45 lines (38 loc) · 880 Bytes
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once
#ifndef UTILS_H
#define UTILS_H
typedef unsigned char BYTE; // 0 to 256
typedef char SIGNED_BYTE; // -128 to 127
typedef unsigned short WORD; // 0 to 65535
typedef signed short SIGNED_WORD; // -32768 to 32767
static bool TestBit(BYTE data, BYTE bitToTest)
{
if (((data >> bitToTest) & 1) == 1) // Corrected condition
{
return true;
}
return false;
}
static BYTE SetBit(BYTE data, BYTE bitToSet)
{
BYTE bitSet = (1 << bitToSet);
data |= bitSet;
return data;
}
static BYTE ResetBit(BYTE data, BYTE bitToReset) // Added return type
{
data = data ^ (0b1 << bitToReset); // XOR the bit so that it becomes 0
return data;
}
static BYTE BitGetVal(BYTE byteToCheck, int bitPos)
{
if(TestBit(byteToCheck, bitPos))
{
return 0b1;
}
else
{
return 0b0;
}
}
#endif