Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

converting a double to cardinal

1,659 views
Skip to first unread message

Leif Lundberg

unread,
Jun 23, 1999, 3:00:00 AM6/23/99
to
I need a routine to convert a double to cardinal(32bit unsigned).
The value of the double will never be negative.

Leif

Guido Gybels

unread,
Jun 23, 1999, 3:00:00 AM6/23/99
to
Hi Leif,

A double is a real number wich occupies 8 bytes. A cardinal is a generic
type, but in 32-bit Delphi it designates a 32 bit unsigned integer. This
means that numbers beyond the range of a 32 bit unsigned value (4294967295)
can not be stored in them. Considering this, you could use Trunc() or
Round().

Guido GYBELS
Programmer (GDG GROEP BELGIUM)

Leif Lundberg heeft geschreven in bericht
<7kqhqo$a2...@forums.borland.com>...

bob mackey

unread,
Jun 23, 1999, 3:00:00 AM6/23/99
to
Leif Lundberg wrote:
>
> I need a routine to convert a double to cardinal(32bit unsigned).
> The value of the double will never be negative.
>
> Leif

Acardinal := trunc(Adouble);
or
Acardinal := round(Adouble);

--
bob
myName = 'bobmackey';
myISP = 'annapolis.net';
myaddress := myName + '@' + myISP;

Leif Lundberg

unread,
Jun 23, 1999, 3:00:00 AM6/23/99
to

Guido Gybels skrev i meddelandet <7kqn0b$a3...@forums.borland.com>...

>Hi Leif,
>
>A double is a real number wich occupies 8 bytes. A cardinal is a generic
>type, but in 32-bit Delphi it designates a 32 bit unsigned integer. This
>means that numbers beyond the range of a 32 bit unsigned value (4294967295)
>can not be stored in them. Considering this, you could use Trunc() or
>Round().


I'm aware of this but I can't use trunc or round, they are returning a
longint I need it to be unsigned 32bit

Here's my problem, In the header of a PDB file (database file for a palm
III) ther is three fields that are numeric and 4bytes eatch, this fields
expresses a date as a number of seconds since january 1 1904.
If a convert a TDatetime of today to seconds the value will be out of bounds
on a longint.
So I need to store my calculated value (double) in 4 byte.

Any ideas?

Leif

Philippe Ranger

unread,
Jun 23, 1999, 3:00:00 AM6/23/99
to
<<Leif:

I need a routine to convert a double to cardinal(32bit unsigned).
The value of the double will never be negative.
>>

Adding to Guido and Bob -- Before D4 "cardinals" are actually integers. You
lose the use of the highest bit, it's still a sign bit.

PhR

Peter Below (TeamB)

unread,
Jun 23, 1999, 3:00:00 AM6/23/99
to
In article <7kr0bt$af...@forums.borland.com>, Leif Lundberg wrote:
> I'm aware of this but I can't use trunc or round, they are returning a
> longint I need it to be unsigned 32bit
>
> Here's my problem, In the header of a PDB file (database file for a palm
> III) ther is three fields that are numeric and 4bytes eatch, this fields
> expresses a date as a number of seconds since january 1 1904.
> If a convert a TDatetime of today to seconds the value will be out of bounds
> on a longint.
> So I need to store my calculated value (double) in 4 byte.
>

Store them in an int64 or COMP and then take the lowermost 4 bytes of that as
your cardinal.

Var
i: int64;
c: Cardinal absolute i;

Begin
i := Round( .... );

If you don't have D4 use COMP instead of int64 and remove the Round, COMP is a
floating point type.

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!


Leif Lundberg

unread,
Jun 23, 1999, 3:00:00 AM6/23/99
to

Peter Below (TeamB) <10011...@compuXXserve.com> skrev i meddelandet ...

>Store them in an int64 or COMP and then take the lowermost 4 bytes of that
as
>your cardinal.
> Var
> i: int64;
> c: Cardinal absolute i;
> Begin
> i := Round( .... );
>If you don't have D4 use COMP instead of int64 and remove the Round, COMP
is a
>floating point type.


I think that's the answer I was looking for, thanks...
Leif


0 new messages