| 18 | |
| 19 | template<typename T> |
| 20 | class BitArray |
| 21 | { |
| 22 | public: |
| 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; |
nothing calls this directly
no outgoing calls
no test coverage detected