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-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: How do I write directly to a memory address? Date: Wed, 09 Feb 2011 10:42:40 +0000 Organization: A noiseless patient Spider Message-ID: References: <67063a5b-f588-45ea-bf22-ca4ba0196ee6@l11g2000yqb.googlegroups.com> <19fh1chm74f9.11cws0j5bckze.dlg@40tude.net> <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> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx03.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="9504"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//quVeI+dy3Q+BQa6UvEfkXuHvfP86p0Q=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (darwin) Cancel-Lock: sha1:5TRYeKplCQjsDb7gXk3+FNF8By4= sha1:7mfvuhsAa5y4clD5nqwGiewMKew= Xref: g2news1.google.com comp.lang.ada:17084 Date: 2011-02-09T10:42:40+00:00 List-Id: "Vinzent Hoefler" <0439279208b62c95f1880bf0f8776eeb@t-domaingrabbing.de> writes: > 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." >>> >>> (byte & (1 << (3 - 1))) >> >> That's not the correct answer. The correct answer is to ask, "Third >> bit from which end?" > > From the less significant end, unless you want the bit numbers to > change when assigned to different sized variables. Well, on big-endian hardware like standard PowerPC, they - in some sense - do. With a project on PowerPC involving lots of different groups/companies, some writing in Ada and some in C, we ended up drawing maps: this is the sort of thing I mean; it describes (the first word of) an NTP datagram, which is sent in network byte order: -- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- |LI | VN |Mode | Stratum | Poll | Precision | -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ (this one is my own work, for project purposes we put the byte numbers in as well). We found that most (UK-raised) programmers could intuit that bit 31 of this 32-bit structure was the lsb of Precision, however unnatural they thought it. I don't think I've ever met anyone who naturally thought big-endian; perhaps it's a first-machine effect.