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,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c9d5fc258548b22a X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!t19g2000prd.googlegroups.com!not-for-mail From: Shark8 Newsgroups: comp.lang.ada Subject: Re: How do I write directly to a memory address? Date: Tue, 8 Feb 2011 17:56:18 -0800 (PST) Organization: http://groups.google.com Message-ID: <0c9a8fbb-465e-4a9b-a9e6-dba67b648283@t19g2000prd.googlegroups.com> References: <67063a5b-f588-45ea-bf22-ca4ba0196ee6@l11g2000yqb.googlegroups.com> <4d4ff70e$0$6886$9b4e6d93@newsspool2.arcor-online.net> <737a6396-72bd-4a1e-8895-7d50f287960e@d28g2000yqc.googlegroups.com> <4d5008a5$0$6879$9b4e6d93@newsspool2.arcor-online.net> <4d5031fe$0$6765$9b4e6d93@newsspool3.arcor-online.net> <1f229967-d3cf-42b6-8087-c97ee08652f3@i40g2000yqh.googlegroups.com> <4d51169e$0$7657$9b4e6d93@newsspool1.arcor-online.net> <1bnp0pw1c8r5b$.guxc48qweiwe.dlg@40tude.net> <4d51a1c0$0$19486$882e7ee2@usenet-news.net> NNTP-Posting-Host: 174.28.151.164 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1297216578 2395 127.0.0.1 (9 Feb 2011 01:56:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 9 Feb 2011 01:56:18 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: t19g2000prd.googlegroups.com; posting-host=174.28.151.164; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 ( .NET CLR 3.5.30729; .NET4.0E),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:18043 Date: 2011-02-08T17:56:18-08:00 List-Id: On Feb 8, 5:13=A0pm, "Randy Brukardt" wrote: > "Shark8" wrote in message > > news:ee766e88-e4c4-4278-8b05-fd0dc9aa3fdb@k17g2000pre.googlegroups.com... > > >> How do you test the third bit of a byte in Ada? > > >One Way, assuming a 1..8 numbering for an 8-bit byte: > > Presuming I *wasn't* interviewing for a job, would be to point out that t= hat > is the wrong question. The question is typically something like testing t= he > ready bit in a device. And the solution to that in Ada is to map the devi= ce > to an appropriate record type, and then read that proper component. For > instance: > > =A0 =A0type Dev_Status is > =A0 =A0 =A0 Read_Ready : Boolean; -- Bit 3. > =A0 =A0 =A0 Write_Ready : Boolean; > =A0 =A0 =A0 ... > =A0 =A0end record; > =A0 =A0for Dev_Status use record > =A0 =A0 =A0 Read_Ready at 0 range 3 .. 3; -- Bit 3. > =A0 =A0 =A0 Write_Ready at 0 range 4 .. 4; > =A0 =A0 =A0 ... > =A0 =A0end record; > > =A0 =A0My_Dev_Status : Dev_Status > =A0 =A0 =A0 with Address =3D> ; > > =A0 =A0 if My_Dev_Status.Read_Ready then -- Testing bit 3. > > QED. :-) > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Randy. That is a far more elegant & practical solution, IMO. The problem really comes into play with the question "How do you set the third bit?" because there is no such context (a device in your example) with which to base your answer, and so you must give an answer somewhat tangential to what the actual practical problem may be. {i.e. it 'works.'}