* Help on bit operation
@ 2009-08-26 23:02 Randi Botse
2009-08-26 23:33 ` Akos Marton
` (3 more replies)
0 siblings, 4 replies; 13+ messages in thread
From: Randi Botse @ 2009-08-26 23:02 UTC (permalink / raw)
To: linux-c-programming
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 majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Help on bit operation
2009-08-26 23:02 Help on bit operation Randi Botse
@ 2009-08-26 23:33 ` Akos Marton
2009-08-26 23:37 ` Uday Verma
` (2 subsequent siblings)
3 siblings, 0 replies; 13+ messages in thread
From: Akos Marton @ 2009-08-26 23:33 UTC (permalink / raw)
To: Randi Botse; +Cc: linux-c-programming
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<nightdecoder@gmail.com> 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 majordomo@vger.kernel.org
> 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 majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Help on bit operation
2009-08-26 23:02 Help on bit operation Randi Botse
2009-08-26 23:33 ` Akos Marton
@ 2009-08-26 23:37 ` Uday Verma
2009-08-26 23:45 ` Ben Rosenberg
2009-08-27 0:15 ` Glynn Clements
3 siblings, 0 replies; 13+ messages in thread
From: Uday Verma @ 2009-08-26 23:37 UTC (permalink / raw)
To: Randi Botse; +Cc: linux-c-programming
If the sizes of your infos is fixed you can do something like this:
info5 = packet & 0x1FF;
info4 = (packet >> 9) & 0x1F;
.. and so on
note that I am masking out unwanted parts of the 32 bit packet using
an all 1s bit pattern 0x1FF : 1 1111 1111, 0x1F : 1 1111. in case of
info4, I first need to move the value 9 bits to the right so that 5
bits of info4 form the LSB.
You can form the packet similarly,
unsigned int packet = ((info1 & 0x3F) << 26) | ((info2 & 0xF) << 22) ...
HTH
packet is your single 32-bit integer which has all these infos encoded.
On Wed, Aug 26, 2009 at 6:02 PM, Randi Botse<nightdecoder@gmail.com> 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 majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
--
Uday
http://soundc.de/
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Help on bit operation
2009-08-26 23:02 Help on bit operation Randi Botse
2009-08-26 23:33 ` Akos Marton
2009-08-26 23:37 ` Uday Verma
@ 2009-08-26 23:45 ` Ben Rosenberg
2009-08-27 0:15 ` Glynn Clements
3 siblings, 0 replies; 13+ messages in thread
From: Ben Rosenberg @ 2009-08-26 23:45 UTC (permalink / raw)
To: Randi Botse; +Cc: linux-c-programming
On Wed, Aug 26, 2009 at 4:02 PM, Randi Botse<nightdecoder@gmail.com> 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 majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
A quick, dirty way of doing it without structs:
#include <stdio.h>
void store_in_int( unsigned int *target, unsigned int offset, size_t
field_sz, unsigned int value ) {
unsigned int mask = ((1<<(field_sz))-1)<<offset;
/* Clear field */
*target |= mask;
*target ^= mask;
/* Load field */
*target |= value<<offset;
}
unsigned int retrieve_from_int( unsigned int target, unsigned int
offset, size_t field_sz ) {
unsigned int mask = ((1<<(field_sz))-1);
return (target>>offset)&mask;
}
int main ( void ) {
unsigned int info=0;
store_in_int(&info, 0, 6, 43);
store_in_int(&info, 6, 4, 11);
store_in_int(&info,10, 8,120);
store_in_int(&info,18, 5, 30);
store_in_int(&info,23, 9,418);
printf("info1: %u\n",retrieve_from_int( info, 0, 6 ));
printf("info2: %u\n",retrieve_from_int( info, 6, 4 ));
printf("info3: %u\n",retrieve_from_int( info,10, 8 ));
printf("info4: %u\n",retrieve_from_int( info,18, 5 ));
printf("info5: %u\n",retrieve_from_int( info,23, 9 ));
return 0;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Help on bit operation
2009-08-26 23:02 Help on bit operation Randi Botse
` (2 preceding siblings ...)
2009-08-26 23:45 ` Ben Rosenberg
@ 2009-08-27 0:15 ` Glynn Clements
2009-08-27 6:43 ` Randi Botse
3 siblings, 1 reply; 13+ messages in thread
From: Glynn Clements @ 2009-08-27 0:15 UTC (permalink / raw)
To: Randi Botse; +Cc: linux-c-programming
Randi Botse 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!.
Two options:
1. Bit fields:
struct information {
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned int information_1 : 6;
unsigned int information_2 : 4;
unsigned int information_3 : 8;
unsigned int information_4 : 5;
unsigned int information_5 : 9;
#else
unsigned int information_5 : 9;
unsigned int information_4 : 5;
unsigned int information_3 : 8;
unsigned int information_2 : 4;
unsigned int information_1 : 6;
#endif
};
2. Shift and mask:
value = value & ~0x3F << 26 | (information_1 & 0x3F) << 26;
value = value & ~0x0F << 22 | (information_2 & 0x0F) << 22;
value = value & ~0xFF << 14 | (information_3 & 0xFF) << 14;
value = value & ~0x1F << 9 | (information_4 & 0x1F) << 9;
value = value & ~0x1FF << 0 | (information_5 & 0x1FF) << 0;
information_1 = value >> 26 & 0x3F;
information_2 = value >> 22 & 0x0F;
information_3 = value >> 14 & 0xFF;
information_4 = value >> 9 & 0x1F;
information_5 = value >> 0 & 0x1FF;
Regarding masks, the following should be memorised:
Hex Binary
0 0000
1 0001
3 0011
7 0111
F 1111
F 1111
E 1110
C 1100
8 1000
0 0000
--
Glynn Clements <glynn@gclements.plus.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Help on bit operation
2009-08-27 0:15 ` Glynn Clements
@ 2009-08-27 6:43 ` Randi Botse
2009-08-28 4:52 ` Randi Botse
0 siblings, 1 reply; 13+ messages in thread
From: Randi Botse @ 2009-08-27 6:43 UTC (permalink / raw)
To: linux-c-programming
Thanks all for the clues!, that's so cool, i can now join and retrieve
informations on that 32bit integer with cool options that you told me.
Thanks you very much!
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Help on bit operation
2009-08-27 6:43 ` Randi Botse
@ 2009-08-28 4:52 ` Randi Botse
2009-08-28 17:02 ` Ben Rosenberg
0 siblings, 1 reply; 13+ messages in thread
From: Randi Botse @ 2009-08-28 4:52 UTC (permalink / raw)
To: linux-c-programming
Hi again.
I was able to solve my bit packing/unpacking problems with bit mask
and shift operations, but i have no idea how to do this using a
bit-field structure, can someone give me a example?
Thanks
- Randi
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Help on bit operation
2009-08-28 4:52 ` Randi Botse
@ 2009-08-28 17:02 ` Ben Rosenberg
[not found] ` <34e1241d0908281139k66e8102dy94b70e9fcfd86763@mail.gmail.com>
0 siblings, 1 reply; 13+ messages in thread
From: Ben Rosenberg @ 2009-08-28 17:02 UTC (permalink / raw)
To: Randi Botse; +Cc: linux-c-programming
On Thu, Aug 27, 2009 at 9:52 PM, Randi Botse<nightdecoder@gmail.com> wrote:
> Hi again.
>
> I was able to solve my bit packing/unpacking problems with bit mask
> and shift operations, but i have no idea how to do this using a
> bit-field structure, can someone give me a example?
>
> Thanks
> - Randi
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
Glynn's example of bitfields is cleaner and better than this, but I
put a basic implementation of bitfields using your parameters at the
end of this message. From my understanding, the way bitfields are
implemented in C is with bit shifts and masks, so I don't think there
is a performance difference between the two.
#include <stdio.h>
struct bitfield {
unsigned int a:6;
unsigned int b:4;
unsigned int c:8;
unsigned int d:5;
unsigned int e:9;
};
int main(void) {
struct bitfield foo;
foo.a = 43;
foo.b = 11;
foo.c = 120;
foo.d = 30;
foo.e = 418;
printf("%u %u %u %u %u\n",foo.a,foo.b,foo.c,foo.d,foo.e);
return 0;
}
Ben
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Help on bit operation
[not found] ` <34e1241d0908281139k66e8102dy94b70e9fcfd86763@mail.gmail.com>
@ 2009-08-28 18:40 ` Randi Botse
2009-08-28 19:58 ` Ben Rosenberg
2009-08-28 20:19 ` Glynn Clements
0 siblings, 2 replies; 13+ messages in thread
From: Randi Botse @ 2009-08-28 18:40 UTC (permalink / raw)
To: linux-c-programming
Ben, after assign all bitfield struct member, how to pack them to be a
32bit integer value?
DEC BIN
43 101011 -> foo.a (6 bit)
11 1011 -> foo.b (4 bit)
120 01111000 -> foo.c (8 bit)
30 11110 -> foo.d (5 bit)
418 110100010 -> foo.e (9 bit)
the bit pattern is : 10101110110111100011110110100010 or 2933800354 in
decimal, is this possible?
while with masking and shift i can pack them with:
((foo.a & 0x3f) << 26) | ((foo.b & 0xf) << 22) | ((foo,c & 0xff) <<
14) | ((foo.d & 0x1f) << 9) | (foo.e & 0x1ff)
On Sat, Aug 29, 2009 at 12:02 AM, Ben Rosenberg<scdlbx@gmail.com> wrote:
> Glynn's example of bitfields is cleaner and better than this, but I
> put a basic implementation of bitfields using your parameters at the
> end of this message. From my understanding, the way bitfields are
> implemented in C is with bit shifts and masks, so I don't think there
> is a performance difference between the two.
>
> #include <stdio.h>
>
> struct bitfield {
> unsigned int a:6;
> unsigned int b:4;
> unsigned int c:8;
> unsigned int d:5;
> unsigned int e:9;
> };
>
> int main(void) {
> struct bitfield foo;
> foo.a = 43;
> foo.b = 11;
> foo.c = 120;
> foo.d = 30;
> foo.e = 418;
> printf("%u %u %u %u %u\n",foo.a,foo.b,foo.c,foo.d,foo.e);
> return 0;
> }
>
>
> Ben
>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Help on bit operation
2009-08-28 18:40 ` Randi Botse
@ 2009-08-28 19:58 ` Ben Rosenberg
2009-08-28 20:14 ` Tim Walberg
2009-08-28 20:19 ` Glynn Clements
1 sibling, 1 reply; 13+ messages in thread
From: Ben Rosenberg @ 2009-08-28 19:58 UTC (permalink / raw)
To: Randi Botse; +Cc: linux-c-programming
On Fri, Aug 28, 2009 at 11:40 AM, Randi Botse<nightdecoder@gmail.com> wrote:
> Ben, after assign all bitfield struct member, how to pack them to be a
> 32bit integer value?
>
> DEC BIN
> 43 101011 -> foo.a (6 bit)
> 11 1011 -> foo.b (4 bit)
> 120 01111000 -> foo.c (8 bit)
> 30 11110 -> foo.d (5 bit)
> 418 110100010 -> foo.e (9 bit)
>
> the bit pattern is : 10101110110111100011110110100010 or 2933800354 in
> decimal, is this possible?
>
> while with masking and shift i can pack them with:
> ((foo.a & 0x3f) << 26) | ((foo.b & 0xf) << 22) | ((foo,c & 0xff) <<
> 14) | ((foo.d & 0x1f) << 9) | (foo.e & 0x1ff)
>
>
The bitfield struct is already packed, you don't need to do anything
else. Just assign values to the different parts.
Ben
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Help on bit operation
2009-08-28 19:58 ` Ben Rosenberg
@ 2009-08-28 20:14 ` Tim Walberg
0 siblings, 0 replies; 13+ messages in thread
From: Tim Walberg @ 2009-08-28 20:14 UTC (permalink / raw)
To: Ben Rosenberg; +Cc: Randi Botse, linux-c-programming
[-- Attachment #1: Type: text/plain, Size: 1747 bytes --]
If you absolutely need to get at the 32-bit integer value, you can use
union mytype {
{ struct bits {
unsigned int a:6;
unsigned int b:4;
unsigned int c:8;
unsigned int d:5;
unsigned int e:9;
} b;
unsigned int v;
} variable;
then access the bit-fields like
unsigned int x = variable.b.e;
variable.b.a = 3;
x = variable.v;
On 08/28/2009 12:58 -0700, Ben Rosenberg wrote:
>> On Fri, Aug 28, 2009 at 11:40 AM, Randi Botse<nightdecoder@gmail.com> wrote:
>> > Ben, after assign all bitfield struct member, how to pack them to be a
>> > 32bit integer value?
>> >
>> > DEC BIN
>> > 43 101011 -> foo.a (6 bit)
>> > 11 1011 -> foo.b (4 bit)
>> > 120 01111000 -> foo.c (8 bit)
>> > 30 11110 -> foo.d (5 bit)
>> > 418 110100010 -> foo.e (9 bit)
>> >
>> > the bit pattern is : 10101110110111100011110110100010 or 2933800354 in
>> > decimal, is this possible?
>> >
>> > while with masking and shift i can pack them with:
>> > ((foo.a & 0x3f) << 26) | ((foo.b & 0xf) << 22) | ((foo,c & 0xff) <<
>> > 14) | ((foo.d & 0x1f) << 9) | (foo.e & 0x1ff)
>> >
>> >
>>
>> The bitfield struct is already packed, you don't need to do anything
>> else. Just assign values to the different parts.
>>
>> Ben
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
End of included message
--
+----------------------+
| Tim Walberg |
| 830 Carriage Dr. |
| Algonquin, IL 60102 |
| twalberg@comcast.net |
+----------------------+
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Help on bit operation
2009-08-28 18:40 ` Randi Botse
2009-08-28 19:58 ` Ben Rosenberg
@ 2009-08-28 20:19 ` Glynn Clements
2009-08-29 7:40 ` Randi Botse
1 sibling, 1 reply; 13+ messages in thread
From: Glynn Clements @ 2009-08-28 20:19 UTC (permalink / raw)
To: Randi Botse; +Cc: linux-c-programming
Randi Botse wrote:
> Ben, after assign all bitfield struct member, how to pack them to be a
> 32bit integer value?
The structure should be 32 bits wide. If you need the value as a
uint32_t, either use a union:
union bits_or_int {
struct bitfield fields;
uint32_t value;
};
or a cast, e.g.:
struct bitfield foo;
...
uint32_t value = *(uint32_t *)&foo;
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Help on bit operation
2009-08-28 20:19 ` Glynn Clements
@ 2009-08-29 7:40 ` Randi Botse
0 siblings, 0 replies; 13+ messages in thread
From: Randi Botse @ 2009-08-29 7:40 UTC (permalink / raw)
To: Glynn Clements; +Cc: linux-c-programming
everything is clear now!, thanks all for your guides and patience.
- Randi
On Sat, Aug 29, 2009 at 3:19 AM, Glynn Clements<glynn@gclements.plus.com> wrote:
>
> Randi Botse wrote:
>
>> Ben, after assign all bitfield struct member, how to pack them to be a
>> 32bit integer value?
>
> The structure should be 32 bits wide. If you need the value as a
> uint32_t, either use a union:
>
> union bits_or_int {
> struct bitfield fields;
> uint32_t value;
> };
>
> or a cast, e.g.:
>
> struct bitfield foo;
> ...
> uint32_t value = *(uint32_t *)&foo;
>
> --
> Glynn Clements <glynn@gclements.plus.com>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2009-08-29 7:40 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-26 23:02 Help on bit operation Randi Botse
2009-08-26 23:33 ` Akos Marton
2009-08-26 23:37 ` Uday Verma
2009-08-26 23:45 ` Ben Rosenberg
2009-08-27 0:15 ` Glynn Clements
2009-08-27 6:43 ` Randi Botse
2009-08-28 4:52 ` Randi Botse
2009-08-28 17:02 ` Ben Rosenberg
[not found] ` <34e1241d0908281139k66e8102dy94b70e9fcfd86763@mail.gmail.com>
2009-08-28 18:40 ` Randi Botse
2009-08-28 19:58 ` Ben Rosenberg
2009-08-28 20:14 ` Tim Walberg
2009-08-28 20:19 ` Glynn Clements
2009-08-29 7:40 ` Randi Botse
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).