* Bitfields
@ 2004-12-01 4:25 Jagadeesh Bhaskar P
2004-12-01 19:44 ` Bitfields HIToC
0 siblings, 1 reply; 3+ messages in thread
From: Jagadeesh Bhaskar P @ 2004-12-01 4:25 UTC (permalink / raw)
To: Linux C Programming
Hi all,
What is a bitfield? How is it used in C??
TIA
--
With regards,
Jagadeesh Bhaskar P
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Bitfields
@ 2004-12-01 10:59 Ronaldo Zacarias Afonso
0 siblings, 0 replies; 3+ messages in thread
From: Ronaldo Zacarias Afonso @ 2004-12-01 10:59 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1: Mail message body --]
[-- Type: text/plain, Size: 990 bytes --]
Hi Jagadeesh,
"bit field" is a way that let you define a varible to be less than a byte
in size. For example: 3 bits.
It is used as structs.
struct nibble {
unsigned int n0: 4;
unsigned int n1: 4;
unsigned int n2: 4;
unsigned int n3: 4;
};
In this way you have declared four variables, each with a size of four
bits.
>Hi all,
> What is a bitfield? How is it used in C??
>
>TIA
>
>--
>With regards,
>
>Jagadeesh Bhaskar P
>
>-
>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
>
>----------
_________________________________________________________________________________
Quer mais velocidade?
Só com o acesso Aditivado iG, a velocidade que você quer na hora que você precisa.
Clique aqui: http://www.acessoaditivado.ig.com.br
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Bitfields
2004-12-01 4:25 Bitfields Jagadeesh Bhaskar P
@ 2004-12-01 19:44 ` HIToC
0 siblings, 0 replies; 3+ messages in thread
From: HIToC @ 2004-12-01 19:44 UTC (permalink / raw)
To: Jagadeesh Bhaskar P; +Cc: Linux C programming
On Wednesday 01 December 2004 05:25, Jagadeesh Bhaskar P wrote:
> Hi all,
> What is a bitfield? How is it used in C??
>
> TIA
It is possible to use several of bit variables like fields within a struct.
You have to indicate first the name of the field, then the number of bits
that the field occupies. Also you have to put double points ":" between
the filed's name and its bit-size.
For example, you want to save the current date; you can define a
struct Date (YYYY/MM/DD) like this
struct Date { // Date format: YYYY/MM/DD
unsigned year : 7; // 0-127 (2000-2127) [7 bits size]
unsigned month : 4; // 1-12 [4 bits size]
unsigned day : 5; // 1-31 [5 bits size]
};
In this case we have the complete date in a 16 bit variable (7+4+5=16 bit)!
--
With regards,
HIToC
hitoc_mail@yahoo.it
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-12-01 19:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-01 4:25 Bitfields Jagadeesh Bhaskar P
2004-12-01 19:44 ` Bitfields HIToC
-- strict thread matches above, loose matches on Subject: below --
2004-12-01 10:59 Bitfields Ronaldo Zacarias Afonso
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).