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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2a0aa2b1c348fd6a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-11!supernews.com!sjc1.usenetserver.com!chi1.usenetserver.com!news.usenetserver.com!newsfeed-east.nntpserver.com!nntpserver.com!newsfeed1.sea.pnap.net!newsfeed2.sea.pnap.net!newsfeed.pnap.net!brmea-news-1.sun.com!news1nwk.sfbay.sun.com!new-usenet.uk.sun.com!not-for-mail From: Ole-Hjalmar Kristensen Newsgroups: comp.lang.ada Subject: Re: shifting bits Date: 30 Aug 2004 11:03:51 +0200 Organization: Sun Microsystems Message-ID: References: NNTP-Posting-Host: khepri06.norway.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: new-usenet.uk.sun.com 1093856632 12742 129.159.112.195 (30 Aug 2004 09:03:52 GMT) X-Complaints-To: usenet@new-usenet.uk.sun.com NNTP-Posting-Date: 30 Aug 2004 09:03:52 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:3156 Date: 2004-08-30T09:03:52+00:00 List-Id: >>>>> "fdf" == fabio de francesco writes: fdf> Hello. fdf> I had to pack/unpack some variables into/from one. In order to get the fdf> result I chose to shift the variables' bits using multiplications and fdf> divisions by powers of two. fdf> 1) Does Ada have a built-in shift operand like C++ "<<" and ">>" ? Yes, defined for modular types. fdf> 2) Can only variables of modular type be shifted ? If yes, why ? Portability, I guess. What happens if you shift a sigend type? If this annoys you, you can always convert to an unsigned type. fdf> 3) Will the following code produce some "shl" and "shr" machine fdf> instruction ? fdf> date_y := date_y * 2**9; -- shift left fdf> year := integer((date / 2**9) and offset_year); --shift right and fdf> "and" offset fdf> I thank you all in advance. fdf> Ciao, fdf> Fabio De Francesco. Have you considered just using a record and specifying which bits should be allocated to the different fields instead? This would save you the trouble of doing the packing/unpacking yourself.... -- C++: The power, elegance and simplicity of a hand grenade.