From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2a0aa2b1c348fd6a,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews2.google.com!not-for-mail From: fmdf@tiscali.it (fabio de francesco) Newsgroups: comp.lang.ada Subject: shifting bits Date: 28 Aug 2004 18:38:42 -0700 Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 80.183.74.82 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1093743523 29212 127.0.0.1 (29 Aug 2004 01:38:43 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 29 Aug 2004 01:38:43 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:3126 Date: 2004-08-28T18:38:42-07:00 List-Id: 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;