, uint8.
, unsigned long
#include <bitset>
template <typename T>
QBitArray toQBit(T val) {
std::bitset<sizeof(T) * 8> bs(val);
QBitArray result(bs.size());
for (int ii = 0; ii < bs.size(); ++ii) {
result.setBit(ii, bs.test(ii));
}
return result;
}
There is no way to generally convert any type of data into a bitmap. Especially if your data type contains pointers, you probably want to wrap the pointer, not the pointer. Therefore, any complex type should be considered separately. And keep abreast of the various endiannes (low-north and big-endian) in different architectures. I think std :: bitset is safe in accordance with this problem, but, for example, casting a pointer to a struct to a char array and storing its bits may be unsafe.
source
share