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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Examining individual bytes of an integer Date: Mon, 15 Oct 2018 09:42:19 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <9d90fa3e-f800-4086-bf97-a65474a8140a@googlegroups.com> NNTP-Posting-Host: MyFhHs417jM9AgzRpXn7yg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 X-Notice: Filtered by postfilter v. 0.8.3 Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:54577 Date: 2018-10-15T09:42:19+02:00 List-Id: On 2018-10-14 21:15, Henrik Härkönen wrote: > I'd like to examine individual bytes of larger (in bit size) integer type. In C would probably move byte pointer etc. Also I'd need to have a way to construct the integer from individual bytes. > > Would this be "the Ada-way", the Unchecked_Conversion? I would say no. I am customary using arithmetic operations in order to serialize and de-serialize integers to/from bit, octet, whatever medium stream. It is the only way which is 100% safe and portable. As an example, here is stream I/O of signed integers using chain code representation: http://www.dmitry-kazakov.de/ada/strings_edit.htm#10.1 -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de