MCPcopy Create free account
hub / github.com/ajkhoury/ReClassEx / BitArray

Class BitArray

ReClass/BitArray.h:20–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19template<typename T>
20class BitArray
21{
22public:
23 BitArray()
24 {
25 value = 0xFF;
26 length = sizeof(T) * CHAR_BIT;
27 size = length + 1;
28 bits = new char[size];
29 }
30
31 BitArray(T num)
32 {
33 value = num;
34 length = sizeof(T) * CHAR_BIT;
35 size = length + 1;
36 bits = new char[size];
37 }
38
39 ~BitArray()
40 {
41 delete[] bits;
42 }
43
44 char* GetBitsString()
45 {
46 for (int i = length - 1; i >= 0; i--)
47 {
48 unsigned char bit = GetBit(i);
49 bits[(length - 1) - i] = bit + 0x30;
50 }
51
52 bits[size - 1] = '\0';
53
54 return bits;
55 }
56
57 char* GetBitsReverseString()
58 {
59 for (int i = 0; i < length; i++)
60 {
61 unsigned char bit = GetBit(i);
62 bits[i] = bit + '0'; // Get ascii representation of bit
63 }
64
65 bits[size - 1] = '\0';
66
67 return bits;
68 }
69
70 //void PrintBit(int index)
71 //{
72 // printf("\nbits[%d] = %d", index, GetBit(index));
73 //}
74
75 unsigned char GetBit(int index)
76 {
77 return (value & (1 << index)) != 0;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected