-1
  1. 24bits corresponds to different parameters, with each parameter taking varying number of bits (taking up value either 1 or 0).
  2. Need to create a byte array (or unsigned char array) so that all these 24bits will fit in and there will be no memory loss (which will happen in case of taking int data type)
  3. Require a byte pointer so that upon incrementing the pointer it would seek the location 0,8,16 in the byte array formed.

I couldnt get a proper method to do it as I couldnt able to access in case of byte array (say from 0 to 23 bits). Kindly help me with this in C program

**Example:**
>**Available-**
>a=0; b=1; c=1; d=0;... till 23 parameters
>**Required-**
>byte arr[3] containing above 23 parameters
>byte *p
>p=arr to access every 8 bit
Taala
  • 41
  • 1
  • 5
  • Possible duplicate of [How do you set, clear and toggle a single bit in C/C++?](http://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit-in-c-c) – phuclv Nov 20 '16 at 09:39
  • Not really. In the above question, only access to bits is the primary concern. Mine is how to access array of bits (array of 24 bits). Hope it is clear now – Taala Nov 20 '16 at 11:10
  • No, your arguments are 24 different variables, each containing on bit. Now just set those 24 bits to the 24 bits in the result. – phuclv Nov 20 '16 at 11:12
  • How do you declare a byte array[3] and concatenate all these individual bits into it. Could you kindly help me with this? – Taala Nov 20 '16 at 11:49

1 Answers1

1

You can use bits field. Where there is a guide Bits field

P.Carlino
  • 661
  • 5
  • 21
  • The tutorial linked to is good; keep in mind also that your compiler may still align values on word boundaries, unless you tell it not to. – hlongmore Nov 20 '16 at 09:43
  • Thank you for responding. I require an array of such fields, array of 3 bytes (which I couldnt get hold off using bitset). – Taala Nov 20 '16 at 09:48