1 // This file was extracted from the TCG Published
2 // Trusted Platform Module Library
3 // Part 4: Supporting Routines
4 // Family "2.0"
5 // Level 00 Revision 01.16
6 // October 30, 2014
7 
8 #include "InternalRoutines.h"
9 //
10 //
11 //           Functions
12 //
13 //            BitIsSet()
14 //
15 //      This function is used to check the setting of a bit in an array of bits.
16 //
17 //      Return Value                          Meaning
18 //
19 //      TRUE                                  bit is set
20 //      FALSE                                 bit is not set
21 //
22 BOOL
BitIsSet(unsigned int bitNum,BYTE * bArray,unsigned int arraySize)23 BitIsSet(
24      unsigned int          bitNum,                    // IN: number of the bit in 'bArray'
25      BYTE                 *bArray,                    // IN: array containing the bit
26      unsigned int          arraySize                  // IN: size in bytes of 'bArray'
27      )
28 {
29      pAssert(arraySize > (bitNum >> 3));
30      return((bArray[bitNum >> 3] & (1 << (bitNum & 7))) != 0);
31 }
32 //
33 //
34 //            BitSet()
35 //
36 //      This function will set the indicated bit in bArray.
37 //
38 void
BitSet(unsigned int bitNum,BYTE * bArray,unsigned int arraySize)39 BitSet(
40      unsigned int          bitNum,                    // IN: number of the bit in 'bArray'
41      BYTE                 *bArray,                    // IN: array containing the bit
42      unsigned int          arraySize                  // IN: size in bytes of 'bArray'
43      )
44 {
45      pAssert(arraySize > bitNum/8);
46      bArray[bitNum >> 3] |= (1 << (bitNum & 7));
47 }
48 //
49 //
50 //           BitClear()
51 //
52 //     This function will clear the indicated bit in bArray.
53 //
54 void
BitClear(unsigned int bitNum,BYTE * bArray,unsigned int arraySize)55 BitClear(
56      unsigned int         bitNum,             // IN: number of the bit in 'bArray'.
57      BYTE                *bArray,             // IN: array containing the bit
58      unsigned int         arraySize           // IN: size in bytes of 'bArray'
59      )
60 {
61      pAssert(arraySize > bitNum/8);
62      bArray[bitNum >> 3] &= ~(1 << (bitNum & 7));
63 }
64