Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Really newbie C question.

Name: Anonymous 2006-03-08 10:49

I'm just starting learning C, and I need some help with an array

char moo[500] would be one byte per element right?
int moo[500] would be two or four bytes per element or whatever.

But is there an easy way to have an array of bits? So its 1 bit per element?

Name: Anonymous 2006-03-09 3:42

the only way to 'extract' the bits from a byte in C is to use shift operations (>> and << binary operators), and you may not be familiar to them yet.

bitwise operators.

To get the contents of 01001010[5] you would do

char c = (01001010 & ((char)(1<<5)))) >> 5

c will now be 0 if bit 5 is 0 and 1 if bit 5 is 1

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List