-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpuint.cpp
37 lines (30 loc) · 872 Bytes
/
cpuint.cpp
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
#include <sstream>
#include "cpuint.h"
using namespace std;
void clearStruct(CPUID_DATA * data) {
data->EAX = 0;
data->EBX = 0;
data->ECX = 0;
data->EDX = 0;
}
string stringFromRaw(char * rawData, uint64_t maxLength) {
string result;
uint64_t index = 0;
while (index < maxLength && rawData[index] != 0) {
result.append(1, rawData[index]);
index++;
}
return result;
}
uint32_t intFromBitRange(uint32_t num, uint8_t lowBit, uint8_t highBit) {
uint8_t maxBit = (8 * sizeof(uint32_t)) - 1;
if (lowBit > maxBit || highBit > maxBit || lowBit > highBit) return num;
uint8_t shift = (maxBit - highBit);
uint32_t result = num << shift;
return result >> (shift + lowBit);
}
bool flagAtIndex(uint32_t num, uint8_t bitIndex) {
uint32_t result = num >> bitIndex;
result &= 1U;
return result;
}