aboutsummaryrefslogtreecommitdiff
path: root/Bits.c
blob: ca473c0d7890a47ebc49727009e0ed36a96740f4 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// This file was extracted from the TCG Published
// Trusted Platform Module Library
// Part 4: Supporting Routines
// Family "2.0"
// Level 00 Revision 01.16
// October 30, 2014

#include "InternalRoutines.h"
//
//
//           Functions
//
//            BitIsSet()
//
//      This function is used to check the setting of a bit in an array of bits.
//
//      Return Value                          Meaning
//
//      TRUE                                  bit is set
//      FALSE                                 bit is not set
//
BOOL
BitIsSet(
     unsigned int          bitNum,                    // IN: number of the bit in 'bArray'
     BYTE                 *bArray,                    // IN: array containing the bit
     unsigned int          arraySize                  // IN: size in bytes of 'bArray'
     )
{
     pAssert(arraySize > (bitNum >> 3));
     return((bArray[bitNum >> 3] & (1 << (bitNum & 7))) != 0);
}
//
//
//            BitSet()
//
//      This function will set the indicated bit in bArray.
//
void
BitSet(
     unsigned int          bitNum,                    // IN: number of the bit in 'bArray'
     BYTE                 *bArray,                    // IN: array containing the bit
     unsigned int          arraySize                  // IN: size in bytes of 'bArray'
     )
{
     pAssert(arraySize > bitNum/8);
     bArray[bitNum >> 3] |= (1 << (bitNum & 7));
}
//
//
//           BitClear()
//
//     This function will clear the indicated bit in bArray.
//
void
BitClear(
     unsigned int         bitNum,             // IN: number of the bit in 'bArray'.
     BYTE                *bArray,             // IN: array containing the bit
     unsigned int         arraySize           // IN: size in bytes of 'bArray'
     )
{
     pAssert(arraySize > bitNum/8);
     bArray[bitNum >> 3] &= ~(1 << (bitNum & 7));
}