I cant think right now and.....

Started by
1 comment, last by Esap1 24 years ago
Could someone write a little C code that loops through chars(1 byte,8 bits) and separates them into bits, in like other variables. I tried using shifts but if didnt work 2 good, Thanks alot
Advertisement
How about something like this: Your input char is c.

bool bit1 = c & 0x01;bool bit2 = c & 0x02;bool bit3 = c & 0x04; 


etc.
Or even cleaner:
bool bits[8];for( int i = 0; i < 8; i++ ){  bits = c & ( 1 << i );} 


#pragma DWIM // Do What I Mean!
~ Mad Keith ~
**I use Software Mode**
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.

void BitSeperator(unsigned char source,char *dest) // dest = pointer to char[8]
{
for (char i=0;i<8;i++)
{
dest = source&1;
source >>=1;
}
}


I hope that''s the right code for you

Visit our homepage: www.rarebyte.de.st

GA
Visit our homepage: www.rarebyte.de.stGA

This topic is closed to new replies.

Advertisement