Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site turtlevax.UUCP Path: utzoo!utcs!lsuc!pesnta!amd!turtlevax!ken From: ken@turtlevax.UUCP (Ken Turkowski) Newsgroups: net.lang.c Subject: How does one construct a mask for the MS bit? Message-ID: <672@turtlevax.UUCP> Date: Wed, 27-Feb-85 16:42:59 EST Article-I.D.: turtleva.672 Posted: Wed Feb 27 16:42:59 1985 Date-Received: Wed, 27-Feb-85 21:27:15 EST Distribution: net Organization: CADLINC, Inc. @ Menlo Park, CA Lines: 36 The VAX and PDP-11 have the property that int x; x = 12000; write(df, &x, 2); gives the same results whether an int is short or long. On the 68000, this gives different results. This could be interpreted as follows: truncation of bytes or words for the DEC computers are appropriate for integers, whereas truncation for the 68000 is appropriate for fractions. Taking the "first" digit of 12345 yields 5 for DEC, and 1 for Motorola. I would like to be able to have the write sequence above give the same results for the 68000, regardless of whether the int is long or short. This would require the generation of a mask for the most significant bit of an int, where the int could be any arbitrary size. Does the following not work on any machine? main() { int x; x = (-1) & ~((unsigned)(-1) >> 1); printf("%x\n", x); } Then I could sequence through bits as follows: for (i = 0; i < N; i++) if (joe & (ms >> i)) printf("Bit %d of joe is set\n", i); -- Ken Turkowski @ CADLINC, Menlo Park, CA UUCP: {amd,decwrl,nsc,seismo,spar}!turtlevax!ken ARPA: turtlevax!ken@DECWRL.ARPA