comp.lang.ada
 help / color / mirror / Atom feed
* shifting bits
@ 2004-08-29  1:38 fabio de francesco
  2004-08-29  3:51 ` Jim Rogers
                   ` (5 more replies)
  0 siblings, 6 replies; 46+ messages in thread
From: fabio de francesco @ 2004-08-29  1:38 UTC (permalink / raw)


Hello.

I had to pack/unpack some variables into/from one. In order to get the
result I chose to shift the variables' bits using multiplications and
divisions by powers of two.

1) Does Ada have a built-in shift operand like C++ "<<" and ">>" ?
2) Can only variables of modular type be shifted ? If yes, why ?
3) Will the following code produce some "shl" and "shr" machine
instruction ?

date_y := date_y * 2**9;	-- shift left	
year := integer((date / 2**9) and offset_year); --shift right and
"and" offset

I thank you all in advance.

Ciao,
Fabio De Francesco.


P.S. The following is the complete code in the case someone wanted to
read it in the whole. I/O routines and values checks have been cut to
the minimum or removed.

with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO;

procedure packed_date is

    type date_type is mod 2**20;
    date, date_y, date_m, date_d : date_type := 0;
    offset_year : constant date_type := 2**11-1;
    offset_month : constant date_type := 2**4-1;
    offset_day : constant date_type := 2**5-1;
    year : integer range 1900 .. 2099 := 1900;
    month : integer range 1 .. 12 := 1;
    day : integer range 1 .. 31 := 1;
    
begin

    get (year);
    date_y := date_type(year);
    date_y := date_y * 2**9;
    get (month);
    date_m := date_type(month);
    date_m := date_m * 2**5;
    get (day);
    date_d := date_type(day);
    date := date_y or date_m or date_d;
    day := integer(date and offset_day);
    put(day);
    month := integer( (date / 2**5) and offset_month );
    put(month);
    year := integer( (date / 2**9) and offset_year );
    put(year);
    
end packed_date;



^ permalink raw reply	[flat|nested] 46+ messages in thread

end of thread, other threads:[~2005-08-10 18:05 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-29  1:38 shifting bits fabio de francesco
2004-08-29  3:51 ` Jim Rogers
2004-08-29  6:51   ` Martin Krischik
2004-08-29 12:53   ` fabio de francesco
2004-08-29 13:21     ` Ludovic Brenta
2004-08-29 17:58       ` Simon Wright
2004-08-29 14:25     ` Michael Bode
2004-08-29 11:29 ` Ludovic Brenta
2004-08-29 17:17   ` tmoran
2004-08-29 13:53 ` Stephen Leake
2004-08-29 17:17 ` tmoran
2004-08-30  3:49   ` fabio de francesco
2004-08-30  4:16     ` tmoran
2004-08-31  0:22       ` fabio de francesco
2004-10-10 17:51     ` ACM Queue Ada article tmoran
2004-10-11 13:13       ` Marc A. Criley
2004-10-12 18:32         ` skidmarks
2004-11-30 18:04     ` SIGAda ad tmoran
2005-05-25  7:19     ` Gnat STORAGE_ERROR tmoran
2005-05-25  8:53       ` Alex R. Mosteo
2005-05-25  9:51         ` Duncan Sands
2005-05-25 10:05           ` Alex R. Mosteo
2005-05-25 11:32             ` Duncan Sands
2005-05-25 12:16               ` Alex R. Mosteo
2005-05-26  9:39                 ` Duncan Sands
2005-05-26  9:53                   ` Alex R. Mosteo
2005-05-26 19:32                   ` Björn Persson
2005-05-25 18:30         ` tmoran
2005-05-26  2:19           ` David C. Hoos, Sr.
2005-05-26 18:42             ` tmoran
2005-05-27  7:19               ` workaround, was " tmoran
2005-07-29 21:08     ` shifting bits tmoran
2005-07-30 20:28     ` Ada utility for Google Earth, NASA World Wind tmoran
2005-08-08 13:27       ` Marc A. Criley
2005-08-08 21:08         ` tmoran
2005-08-10  8:11         ` Rob Norris
2005-08-10  8:35           ` tmoran
2005-08-10 11:41             ` Rob Norris
2005-08-10 18:05               ` tmoran
2004-08-30  9:03 ` shifting bits Ole-Hjalmar Kristensen
2004-08-30 11:37   ` Dale Stanbrough
2004-08-30 18:38     ` Jeffrey Carter
2004-08-30 15:19 ` Martin Krischik
2004-08-30 17:17   ` Georg Bauhaus
2004-08-30 18:48     ` Jeffrey Carter
2004-08-31 12:37       ` Georg Bauhaus

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