All of lore.kernel.org
 help / color / mirror / Atom feed
From: HIToC <hitoc_mail@yahoo.it>
To: Jagadeesh Bhaskar P <jbhaskar@hclinsys.com>
Cc: Linux C programming <linux-c-programming@vger.kernel.org>
Subject: Re: Bitfields
Date: Wed, 1 Dec 2004 20:44:38 +0100	[thread overview]
Message-ID: <200412012042.09952.hitoc_mail@yahoo.it> (raw)
In-Reply-To: <1101875142.7423.2.camel@myLinux>

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


  reply	other threads:[~2004-12-01 19:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-01  4:25 Bitfields Jagadeesh Bhaskar P
2004-12-01 19:44 ` HIToC [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-12-01 10:59 Bitfields Ronaldo Zacarias Afonso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200412012042.09952.hitoc_mail@yahoo.it \
    --to=hitoc_mail@yahoo.it \
    --cc=jbhaskar@hclinsys.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.