Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Macro to calculate seconds of a year ( 16 bit processor)

Reply
Thread Tools

Macro to calculate seconds of a year ( 16 bit processor)

 
 
Shilpa
Guest
Posts: n/a
 
      11-20-2006
Hi
Can anyone guide me by providing me the code ,for the following
requirement:
how to write a macro for a 16 bit processor that returns the
calculated seconds of a year assuming 365 days in a year ?

Thanking you in advance

 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      11-20-2006
"Shilpa" <> wrote:

> Hi
> Can anyone guide me by providing me the code ,for the following
> requirement:
> how to write a macro for a 16 bit processor that returns the
> calculated seconds of a year assuming 365 days in a year ?


#define NUMBER_OF_SECONDS_IN_A_SHORT_YEAR 31536000L

HTH; HAND.

Richard
 
Reply With Quote
 
 
 
 
Barry Schwarz
Guest
Posts: n/a
 
      11-20-2006
On 20 Nov 2006 03:44:23 -0800, "Shilpa" <>
wrote:

>Hi
> Can anyone guide me by providing me the code ,for the following
>requirement:
> how to write a macro for a 16 bit processor that returns the
>calculated seconds of a year assuming 365 days in a year ?
>


In C, macros do not perform calculations. Nor are they functions so
they don't return anything. They serve only two purposes:

They define macro names whose existence can be tested for by
certain preprocessor directives.

They identify text substitutions that are to be performed by the
preprocessor.

Since the maximum value allowed in a 16 bit variable is 65535 and the
number of seconds in a year is on the order of 31.5 million, maybe you
could rephrase your request so we know what you really want.


Remove del for email
 
Reply With Quote
 
dcorbit@connx.com
Guest
Posts: n/a
 
      11-20-2006

Shilpa wrote:
> Hi
> Can anyone guide me by providing me the code ,for the following
> requirement:
> how to write a macro for a 16 bit processor that returns the
> calculated seconds of a year assuming 365 days in a year ?
>
> Thanking you in advance


There are not 365 days in a year. If you start with a wrong
assumption, you end up with wrong answers.

P.S.
There are 86,400 seconds in a day (ignoring leap seconds)

P.P.S.
If you want the right answer, you can't ignore leap seconds

P.P.P.S.
Leap seconds are pretty rare, I suggest a table lookup.

 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      11-20-2006
In article <>,
Barry Schwarz <> wrote:
>On 20 Nov 2006 03:44:23 -0800, "Shilpa" <>
>wrote:


>> how to write a macro for a 16 bit processor that returns the
>>calculated seconds of a year assuming 365 days in a year ?


>Since the maximum value allowed in a 16 bit variable is 65535 and the
>number of seconds in a year is on the order of 31.5 million, maybe you
>could rephrase your request so we know what you really want.


On the other hand, a "16 bit processor" is not necessarily
restricted to 16 bit variables -- but it probably would have trouble
if the macro expanded to more than 65535 characters
--
Prototypes are supertypes of their clones. -- maplesoft
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      11-20-2006
writes:
[...]
> There are not 365 days in a year. If you start with a wrong
> assumption, you end up with wrong answers.


There are 365 days in *this* year. (The word "year" is ambiguous.)

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
Shilpa
Guest
Posts: n/a
 
      11-21-2006
Barry Schwarz wrote:
> On 20 Nov 2006 03:44:23 -0800, "Shilpa" <>
> wrote:
>
> >Hi
> > Can anyone guide me by providing me the code ,for the following
> >requirement:
> > how to write a macro for a 16 bit processor that returns the
> >calculated seconds of a year assuming 365 days in a year ?
> >

>
> In C, macros do not perform calculations. Nor are they functions so
> they don't return anything. They serve only two purposes:
>
> They define macro names whose existence can be tested for by
> certain preprocessor directives.
>
> They identify text substitutions that are to be performed by the
> preprocessor.


Hey u r rite in making me understand what a macro is used for. I do
know macros cannot return values, i think i put my question in a wrong
way

> Since the maximum value allowed in a 16 bit variable is 65535 and the
> number of seconds in a year is on the order of 31.5 million, maybe you
> could rephrase your request so we know what you really want.


What I wanted to ask is how to display such a large value in the 16-bit
variables. I guess we have to use array of integers, but how to proceed
after that.

> Remove del for email


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      11-21-2006
"Shilpa" <> writes:
[...]
> Hey u r rite in making me understand what a macro is used for.

[...]

Please don't use silly abbreviations like 'u' and 'r' here.

> What I wanted to ask is how to display such a large value in the 16-bit
> variables. I guess we have to use array of integers, but how to proceed
> after that.


A 16-bit variable can only hold 65536 distinct values; if it's a
signed integer, it can't hold a value greater than 32767. But why do
you assume you can only use 16-bit variables? Even on a so-called
"16-bit" machine, C requires for at least 32-bit types (64-bit for
C99).

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      11-21-2006
Shilpa wrote:
> Barry Schwarz wrote:
> > On 20 Nov 2006 03:44:23 -0800, "Shilpa" <>
> > wrote:
> >
> > >Hi
> > > Can anyone guide me by providing me the code ,for the following
> > >requirement:
> > > how to write a macro for a 16 bit processor that returns the
> > >calculated seconds of a year assuming 365 days in a year ?

<snip>
> > Since the maximum value allowed in a 16 bit variable is 65535 and the
> > number of seconds in a year is on the order of 31.5 million, maybe you
> > could rephrase your request so we know what you really want.

>
> What I wanted to ask is how to display such a large value in the 16-bit
> variables. I guess we have to use array of integers, but how to proceed
> after that.


In standard C, the type unsigned long int is atleast 32 bits and so
will be more than sufficient for your purpose.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert Seconds to X Hours Y Minutes Z Seconds? 00_CP_D12 ASP .Net 3 02-22-2008 10:37 AM
convert seconds to hours:minutes:seconds `p Ruby 7 12-14-2005 03:32 PM
1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds Michael Tan Ruby 32 07-21-2005 03:23 PM
Convert seconds to minutes and seconds tshad ASP .Net 7 03-11-2005 11:27 PM
Converting seconds to (Days, Hours, Minutes, seconds) Stu C Programming 7 03-07-2005 08:44 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57