comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: Conversion to UNIX time
Date: 2000/07/19
Date: 2000-07-19T20:22:36+00:00	[thread overview]
Message-ID: <u4s5lop1z.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: 20000719014423.05992.00000168@ng-fz1.aol.com

tennisbb@aol.com (Tennisbb) writes:

> My project has decided to name recording files (of which there will probably be
> MANY) by a number of fields, the first two of which will be Start Time and End
> Time in 8-digit Hex UNIX time.  Despite our wide use of re-use, I can't locate
> any routines to convert Calendar Time to an 8-digit Hex string, and wondered if
> anyone has any procedures they'd be willing to share...  The reason for the Hex
> times is to reduce the search time later.  

Below is code to produce hex strings from unsigned integers. If you
can convert time to an unsigned integer, you're all set.

-- 
-- Stephe

-- Abstract:
--
-- Generic plain Hexadecimal image
--
generic
   Width : Natural;
   type Number_Type is mod <>;
function Sal.Generic_Hex_Image (Item : in Number_Type) return String;
-- Return a hexadecimal image of Item, padded with leading zeros to Width.
-- If Width is too small for Item, leading digits are silently truncated.

-- Abstract:
--
-- see spec
--
function Sal.Generic_Hex_Image (Item : in Number_Type) return String
is
   Temp : Number_Type := Item;
   Nibble : Number_Type;
   Image : String (1 .. Width);
begin
   for I in reverse Image'Range loop
      Nibble := Temp mod 16;
      Temp := Temp / 16;
      if Nibble > 9 then
         Image (I) := Character'Val (Character'Pos ('A') + Nibble - 10);
      else
         Image (I) := Character'Val (Character'Pos ('0') + Nibble);
      end if;
   end loop;
   return Image;
end Sal.Generic_Hex_Image;




  reply	other threads:[~2000-07-19  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-07-19  0:00 Conversion to UNIX time Tennisbb
2000-07-19  0:00 ` Stephen Leake [this message]
2000-07-20  0:00   ` tmoran
2000-07-20  0:00 ` Keith Thompson
2000-07-28  0:00 ` Robert I. Eachus
2000-07-27  0:00   ` Keith Thompson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox