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!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!wn11feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada Subject: Re: shifting bits From: Jim Rogers References: Message-ID: User-Agent: Xnews/5.04.25 Date: Sun, 29 Aug 2004 03:51:35 GMT NNTP-Posting-Host: 12.73.180.60 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1093751495 12.73.180.60 (Sun, 29 Aug 2004 03:51:35 GMT) NNTP-Posting-Date: Sun, 29 Aug 2004 03:51:35 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:3127 Date: 2004-08-29T03:51:35+00:00 List-Id: fmdf@tiscali.it (fabio de francesco) wrote in news:ba2f9c57.0408281738.61a48643@posting.google.com: > 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 ">>" ? Ada provides similar bit shifting operations in the package Interfaces. Those operations are defined for specific instances of modular types. > 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