BYTE to binary conversion
-
Hi all, if I have BYTE bTemp = 0xAB; I need the binary stream of this BYTE value(ie 010101011) in to an integer Array. Is there any short way to do that rather to write the code to convert it? Thanks M Chauhan
-
Hi all, if I have BYTE bTemp = 0xAB; I need the binary stream of this BYTE value(ie 010101011) in to an integer Array. Is there any short way to do that rather to write the code to convert it? Thanks M Chauhan
-
Hi all, if I have BYTE bTemp = 0xAB; I need the binary stream of this BYTE value(ie 010101011) in to an integer Array. Is there any short way to do that rather to write the code to convert it? Thanks M Chauhan
Try it :) :
void TranslateBits(CArray<int>* pcArray, BYTE* pbyData, size_t cbDataSize)
{
if (pcArray && pbyData && cbDataSize) {
for (int i = 0; i < cbDataSize; i++) {
BYTE byData = pbyData[i];
for (int j = 0; j < 8; j++) {
int iBit = byData & 1;
byData >> 1;
pcArray->Add(iBit);
}
}
}
}void Usage()
{
BYTE byData(0xAB);
CArray<int> cBitsArray;
TranslateBits(&cBitsArray, &byData, sizeof(byData));
}virtual void BeHappy() = 0;
-
use memcpy but be aware of data size types.
Press F1 for help or google it. Greetings from Germany