Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Esap1

I cant think right now and.....

This topic is 6941 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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**

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!