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 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: Re: shifting bits Date: 29 Aug 2004 05:53:34 -0700 Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 80.183.74.82 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1093784014 25294 127.0.0.1 (29 Aug 2004 12:53:34 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 29 Aug 2004 12:53:34 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:3134 Date: 2004-08-29T05:53:34-07:00 List-Id: Jim Rogers wrote in message news:... > fmdf@tiscali.it (fabio de francesco) wrote in > news:ba2f9c57.0408281738.61a48643@posting.google.com: > > > 2) Can only variables of modular type be shifted ? If yes, why ? > > Even in C and C++ bit shifting is only correct for unsigned types. > Think about what would happen if you shift a sign bit. The > resulting values would be really nasty depending upon the state of > the sign bit. > > Modular types are Ada's unsigned types. > > Jim Rogers Talking about C/C++ you may want to shift a signed numeric variable one position by one to the right in order to either inspect or print each single bit that composes the number. In low-level code, If you know what you are shifting and why, you won't have any bad result. May be that I'm used to Assembly where you often do shifting with every type of value for the most unthinkable reason. Regards, Fabio De Francesco