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.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8f01d35116e753b6 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.235.4 with SMTP id ui4mr17007851pbc.3.1332703595314; Sun, 25 Mar 2012 12:26:35 -0700 (PDT) Path: z9ni684pbe.0!nntp.google.com!news2.google.com!goblin3!goblin2!goblin.stu.neva.ru!news.internetdienste.de!news.tu-darmstadt.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: xor Date: Sun, 25 Mar 2012 22:26:32 +0300 Organization: Tidorum Ltd Message-ID: <9t99r9F6e2U1@mid.individual.net> References: <9t8mq9Fla4U1@mid.individual.net> Mime-Version: 1.0 X-Trace: individual.net OHcn0xAosm3a5LX4s256VwgAQM3Va7SA0aie7iG55AP+53HjAQ Cancel-Lock: sha1:7WroodulJbmqJy7sDXFZS2UeOmQ= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-03-25T22:26:32+03:00 List-Id: On 12-03-25 18:16 , Michael Moeller wrote: > Thank you for your quick answer. > > Can I use Unsigned_Byte_T to read in a byte from a file > as in C? I haven't looked into this yet. C has several ways to "read in a byte from a file", depending on the type of the file and how you specify which byte you want to read. Can you be more specific? If you mean reading an 8-bit octet from a "binary file" -- that is, not a text file -- you can use the Ada library packages Ada.Sequential_IO or Ada.Direct_IO, depending on your needs. These are generic packages, so you must instantiate them for the type of data, for example Unsigned_Byte_T. If the file contains a mixture of different kinds of "binary" data, for example both 8-bit data and 16-bit data, or more complex structures, you should use the Ada "stream" facility from Ada.Streams.Stream_IO. The stream facility helps you handle things like different endianness, padding, packing, unusual encodings, and so on. The stream facility does not use generics; instead, it uses a combination of tagged types and the special "stream attribute" operations T'Read, T'Write, et cetera, which you can define differently for each type, T, that is present in your file. For example, your 'Read operation for a 16-bit integer will specify whether the integer is stored in little-endian or big-endian order in the file (by reading two 8-bit integers, using 'Read for the 8-bit type, in the corresponding order). The stream technique takes a bit of study to understand, but it works very well, especially if the file has a mixture of different complex structures of data, or if the file is created by a different language or computer and is not in the "native" form for your Ada compiler. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .