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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,36b77e6f303e7a0b X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!newshub.sdsu.edu!news.glorb.com!newsfeed-east.nntpserver.com!nntpserver.com!manticore.nntpserver.com.POSTED!teranews!not-for-mail From: Martin Krischik Subject: Re: Printing out an Array Newsgroups: comp.lang.ada Reply-To: martin@krischik.com References: <1107182585.066205.21490@f14g2000cwb.googlegroups.com> Organization: None User-Agent: KNode/0.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit NNTP-Posting-Date: Mon, 31 Jan 2005 11:00:06 EST Message-ID: <1107187206.3dac65443e4e46c0eb33d821093696b6@teranews> X-Abuse-Report: http://www.usenetabuse.com X-Abuse-Notes: Abuse reports must be submited via the usenetabuse.com portal listed above. X-Abuse-Notes2: Reports sent via any other method will not be processed. X-Abuse-Notes3: Any other abuse reporting headers in this article are fraudulent. Date: Mon, 31 Jan 2005 16:00:15 +0100 Xref: g2news1.google.com comp.lang.ada:8089 Date: 2005-01-31T16:00:15+01:00 List-Id: conchale@mac.com wrote: > Hello all, I'm new to this and comming from Java environment. I have > this code to convert bytes to bits but I dont know what to put in the > last line of code to get on the screen my converted number. Thanks for > any help > ---------------------------------------------------------- > with Ada.Text_Io; use Ada.Text_Io; > with Ada.Integer_text_Io; use Ada.Integer_text_Io; > > procedure Pas3 is > > subtype Octet is Integer range 0..255; > subtype Bit is Integer range 0..1; > type Tab_Bits is array (0 .. 7) of Bit; > > function Octet_Vers_Bits (Oc : Octet ) > return Tab_Bits is > Resultat : Tab_Bits; > N : Octet; > > begin > N := Oc; > for I in reverse 0..7 loop > if ( N mod 2 = 1 ) then > Resultat(I) := 1; > else > Resultat(I) := 0; > end if; > N := N / 2; > end loop; > return Resultat; > end Octet_Vers_Bits; > > t1 : Tab_bits; > x : integer; > > begin > Put (" donner x: "); > Get(x); > > > for I in 0 .. 7 loop Read: http://en.wikibooks.org/wiki/Programming:Ada:Control#for_loop_on_arrays You will need tp wait for the next version of Java for that feature ;-). > t1 := Octet_Vers_Bits(x); > Put(Bit(x)); ----------------> here is the problem, what should I > put here. > end loop; > end Pas3 ; Two options open: 1) you can use the 'Image attribute to convert the integer to a string. 2) you can use Ada.Text_IO.Integer_IO to write the value. Option 1 is quickly implemented but you can't format the value. Option 2 is more difficult but you can use formating options. You find wxamples for option 2 here: http://en.wikibooks.org/wiki/Programming:Ada:Types:range Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com