Array of bits?

This is a discussion on Array of bits? within the C Programming forums, part of the General Programming Boards category; Hello I would like to be able to create an array of (for example) 16 or 18 or 40 or ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    18

    Array of bits?

    Hello

    I would like to be able to create an array of (for example) 16 or 18 or 40 or 100 bits.

    I'm aware I can create an array of unsigned chars and simply use the bits I want from that, but I'd prefer a custom bit array which I can operate on as a whole without worrying about which byte (i.e. unsigned char array element) my bit is in.

    Is this possible?

    Any pointers appreciated.

    Thanks.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If you have a struct, you're allowed such a thing as a bitfield -- but you can't access bits using array notation (they're really just variably-sized ints) or anything like that. So that's probably not what you wanted at all.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    18
    Thanks for the replies.

    Dave_Sinkula: would I be able to perform shifts (e.g. >>) using a bit set?

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    You could write a function similar to this, I suppose.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User
    Join Date
    Mar 2008
    Posts
    18
    Thanks Dave.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating a array of 50 bits
    By rohit_second in forum C Programming
    Replies: 5
    Last Post: 01-25-2009, 06:23 PM
  2. Replies: 7
    Last Post: 11-25-2008, 12:50 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21