Timestamp header

S

sriram

Hi all
I want to create a timestamp header in my program which keeps track of
the event number and the exp.num.
Can anyone plz provide a C program to do one such.
The header is of 1byte and 2 bits for the exp number and remaining for
the event number.
Thanks in advance
sriram
 
M

Malcolm

sriram said:
I want to create a timestamp header in my program which keeps track > of
the event number and the exp.num.
Can anyone plz provide a C program to do one such.
The header is of 1byte and 2 bits for the exp number and remaining for
the event number.
I'm afraid that you are not specifying your problem very well.
By "byte" do you mean 8 bits? Or do you mean the smallest addressable unit
of memory on whatever architecture you happen to be running on?

What do you mean by "whatever remaining?" Do you mean that byte-2 bits
should be the event number?

Anyway, you probably want this

typedef struct
{
unsigned int expnum : 10;
unsigned int eventnum : 6;
} HEADER;

This will give you 10 bits for expnum, and 6 bits for eventnum.

If you really do mean "architecture-dependent minimum unit of addressable
memory" by byte, then unfortunately the problem becomes a lot more
complicated. You will have to mess about with the constant CHAR_BIT to make
the bitfields the right size.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,206
Latest member
Zenden

Latest Threads

Top