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=-0.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, FREEMAIL_REPLY autolearn=no 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!news2.google.com!proxad.net!newsfeed.stueberl.de!npeer.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!news.online.de!not-for-mail From: Michael Bode Newsgroups: comp.lang.ada Subject: Re: shifting bits Date: Sun, 29 Aug 2004 16:25:06 +0200 Organization: 1&1 Internet AG Message-ID: <87hdqm58e5.fsf@code-hal.de> References: NNTP-Posting-Host: pd9eac888.dip0.t-ipconnect.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: online.de 1093789506 9455 217.234.200.136 (29 Aug 2004 14:25:06 GMT) X-Complaints-To: abuse@einsundeins.com NNTP-Posting-Date: Sun, 29 Aug 2004 14:25:06 +0000 (UTC) X-message-flag: IMPORTANT MESSAGE -- PLEASE READ IMMEDIATELY!!! X-Accepted-File-Formats: ASCII, .rtf, .ps, .pdf - *NO* MS Office files User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:0D9Q7ArRuTlG7yOLjTDlo6+FO+A= Xref: g2news1.google.com comp.lang.ada:3138 Date: 2004-08-29T16:25:06+02:00 List-Id: fmdf@tiscali.it (fabio de francesco) writes: > 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. So you are viewing your integer or float number as an array of single bits, right? Maybe you want to manipulate single bits in random order too? In Ada you can write it that way: with Ada.Text_Io; use Ada.Text_Io; procedure Bits is type Bit_Array is array (0 .. Integer'Size-1) of Boolean; pragma Pack (Bit_Array); I : Integer := 42; A : Bit_Array; for A'Address use I'Address; Bool_Image : array (Boolean'Range) of Character := ('0', '1'); begin Put_Line ("Int: " & Integer'Image (I)); for J in reverse 0 .. Integer'Size-1 loop Put (Bool_Image (A (J))); end loop; end Bits;