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,ddd2479bb7fae4af X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!news.zanker.org!border2.nntp.ams.giganews.com!nntp.giganews.com!lightspeed.eweka.nl!feeder.news-service.com!post.news-service.com!news1.surfino.com!not-for-mail Message-Id: <2092747.1qBBMuiTJs@linux1.krischik.com> From: Martin Krischik Subject: Re: Bit manipulation Newsgroups: comp.lang.ada Reply-To: martin@krischik.com Date: Mon, 07 Feb 2005 14:20:46 +0100 References: <211db0ae.0502070437.54add641@posting.google.com> Organization: None User-Agent: KNode/0.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@surfino.com NNTP-Posting-Host: 83.169.148.166 (83.169.148.166) NNTP-Posting-Date: Mon, 07 Feb 2005 15:00:10 +0100 X-Trace: be35e4207746af60c310315224 Xref: g2news1.google.com comp.lang.ada:8179 Date: 2005-02-07T14:20:46+01:00 List-Id: Maurizio wrote: > hi, i need two hint: > > i need to acces to a 32 bit word (Interfaces.Unsigned_32). > how i can do to take the three m.s.bit? (30,31,32) Have you considered using a packed array? http://en.wikibooks.org/wiki/Programming:Ada:Types:array#with_aliased_elements Prehaps on conjunction with Unchecked_Conversion. > second, i need to send the 32 bit word over a Tcp connection to a C > program, but > socket work with usigned 8 bit word, so i need to split the 32 bit in > 4 8bit word, > and when i read from the socket take 4 8bit word and combine in a 32 > word. > > i see that Ada.Unchecked_Conversion work (in an ada client/server test > program) but is correct? > > --com_buffer_type is an array of 128 32bit word > > subtype Datas is Ada.Streams.Stream_Element_Array(1..512); --128*4 Stream Elements are normaly not used directly. Ada.Streams only provide a framework for the 'Read, 'Write, 'Input, and 'Output attributes. If you know Java: It works a bit like the Serializable interface. 'Read, 'Write are low level - reading and writing raw data. 'Input, and 'Output are high level - storing array bound, object type etc. pp. as well. > function To_Raw is > new Ada.Unchecked_Conversion > ( > Source => Com_Buffer_Type, --Interfaces.Unsigned_32 > Target => Datas); --Stream_Element is mod 2 ** > Standard'Storage_Unit > function From_Raw is > new Ada.Unchecked_Conversion > ( > Source => Datas, > Target => Com_Buffer_Type); You should give com_buffer_type'Write (Stream, Datas) a try. Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com