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=ham 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: g2news1.google.com!postnews.google.com!y12g2000prf.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: How do I write directly to a memory address? Date: Tue, 8 Feb 2011 14:41:30 -0800 (PST) Organization: http://groups.google.com Message-ID: <505a0855-ed01-4819-9d8e-025ad8d5cb51@y12g2000prf.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> <87411ec5-c197-4143-8ef1-ab9ddb20bcc6@q40g2000prh.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1297204891 5031 127.0.0.1 (8 Feb 2011 22:41:31 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 8 Feb 2011 22:41:31 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: y12g2000prf.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:17061 Date: 2011-02-08T14:41:30-08:00 List-Id: On Feb 8, 1:16=A0pm, "Vinzent Hoefler" <0439279208b62c95f1880bf0f8776...@t-domaingrabbing.de> wrote: > Adam Beneschan wrote: > > On Feb 8, 12:01 pm, Hyman Rosen wrote: > >> On 2/8/2011 2:43 PM, Dmitry A. Kazakov wrote: > > >> > Three candidates in a row I have interviewed for a C/C++/C# position= could > >> > not answer the question how to test the 3rd bit of a byte in C. All = three > >> > had 3+ years of programming "experience." > > >> =A0 =A0 =A0(byte & (1 << (3 - 1))) > > > That's not the correct answer. =A0The correct answer is to ask, "Third > > bit from which end?" > > =A0From the less significant end, unless you want the bit numbers to chan= ge when > assigned to different sized variables. The original question was how to test the 3rd bit of a *byte* (let's assume "byte" means 8 bits), not how to test the 3rd bit of an mathematical integer value that could be stored in variables of different sizes. If someone were talking about the 3rd bit of anything, then 99.9% of the time it would be in the context of some data record with fixed-size fields and where some of those fields are bit fields compressed into a byte or into some *known* larger word size. (Typical when dealing with hardware---and writing directly into hardware what the original question was about, approximately 130 posts ago!) In any event, although I don't recall seeing the terms "the first bit", "the second bit", etc., all that often, I've seen plenty of times when descriptions of (say) hardware device registers or process control structures on a processor or packets communicated between computers use the terms "bit 0", "bit 1", "bit 2"---and I've seen those terms used both ways, i.e. where bit 0 refers to the high- order bit, or where it refers to the low-order bit. Thus, if someone asked me to write code to test either "bit 2 of a byte" or "the third bit of a byte", I would definitely need to ask for clarification. -- Adam