Re: Help on bit operation

Akos Marton <[email protected]>
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <[email protected]>
Hello Randi,

I suppose for you the bitfields is useful:
struct {
  int information_1: 6;
  int information_2: 4;
  int information_3: 8;
  int information_4: 5;
  int information_5: 9;
};
This solution is reduce the usage of memory, but needs more
computation in general C programming.
May there another solution using 'union {};' ?

mAkos

On Thu, Aug 27, 2009 at 1:02 AM, Randi Botse<[email protected]> wrote:
> Hi, I'm beginner C programmer, i have a problem, i want to store some
> information in a integer, a integer will be 32 bit on my machine, i
> want to have as follow:
>
> 6 bit (information 1)   MSB
> 4 bit (information 2)
> 8 bit (information 3)
> 5 bit (information 4)
> 9 bit (information 5)   LSB
>
> For example i set the informations as follow (in decimal):
>
> information 1 = 43        or 101011
> information 2 = 11        or 1011
> information 3 = 120      or 1111000
> information 3 = 30        or 11110
> information 4 = 418      or 110100010
>
> if i join all informations i should get a 32 bit integer valued
> 2935782212 or 01010111011111100011110110100010, then my problem is how
> to retrieve these informations on bit operation? i want to know what's
> the value of information-2 or information-3, etc directly.  And, is
> there any good way to join these informations to be an 32 bit integer?
>
> at this time i convert the 32bit integer into binary string, process
> it's with array segment to get all informations then convert them to
> integer,
> to build the 32bit integer, i join all information value into binary
> string (yes, 32 bit of char ;p) join all of them then convert to
> integer.
>
> I know my way is sucks and too far away from COOL thing ;p,  i think
> there are cool way to do this!.
>
> Thanks before!
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to [email protected]
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>



-- 
People seldom notice clothes, if you wear a big smile.
http://counter.li.org/
OLVASD: http://napirajz.hu
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.