Software & Finance Forums

### Author Topic: accessing bits  (Read 1022 times)

#### thrushitha

• Full Member
• Posts: 26
##### accessing bits
« on: August 25, 2011, 09:29:56 pm »
Hi..

i have a variable say, a[0], wherein 0 occupies 1 byte location, which ha 8 bits.. i.e, 1 byte = 8 bits.
consider ,, a[0]= { 1, 2,3,4,5,6,7,8}
i need to point to 5,, how to do it ??

• Full Member
• Posts: 69
##### Re: accessing bits
« Reply #1 on: August 26, 2011, 07:50:34 am »
Hi..

i have a variable say, a[0], wherein 0 occupies 1 byte location, which ha 8 bits.. i.e, 1 byte = 8 bits.
consider ,, a[0]= { 1, 2,3,4,5,6,7,8}
i need to point to 5,, how to do it ??

int ConvertByteToCharBitsArray(char byte, char *arrBits, int len)
{
if(len !=
return -1;
for(int i = 0; i < len; i++)
{
if(byte & 0x80)
arrBits = 1;
else
arrBits = 0;
byte <<= 1;
}

return 0;
}

int main()
{
char buf[8];
ConvertByteToCharBitsArray(0xF5, buf, ;

for(int i = 0; i < 8; i++)
{
// Bit 0 in the output is MSB
std::cout << "Bit " << i << ": " << (int) buf << "\n";
}
return 0;
}

Bit 0: 1
Bit 1: 1
Bit 2: 1
Bit 3: 1
Bit 4: 0
Bit 5: 1
Bit 6: 0
Bit 7: 1
Press any key to continue . . .

#### thrushitha

• Full Member
• Posts: 26
##### Re: accessing bits
« Reply #2 on: August 28, 2011, 11:05:30 pm »
thank u sir

Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.