Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site inset.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!whuxl!whuxlm!akgua!mcnc!philabs!cmcl2!seismo!mcvax!ukc!qtlon!ist!inset!dave From: dave@inset.UUCP (Dave Lukes) Newsgroups: net.lang.c Subject: Re: How does one construct a mask for the MS bit? Message-ID: <520@inset.UUCP> Date: Wed, 20-Mar-85 12:49:07 EST Article-I.D.: inset.520 Posted: Wed Mar 20 12:49:07 1985 Date-Received: Tue, 26-Mar-85 06:56:56 EST References: <8849@brl-tgr.ARPA>, <169@dmsd.UUCP> Organization: The Instruction Set Ltd, London Lines: 42 Newsgroups: net.lang.c Subject: Re: How does one construct a mask for the MS bit? References: <8849@brl-tgr.ARPA>, <169@dmsd.UUCP> > seems that this should work: > > #define MSB(a) (1<<((sizeof a) * 8 - 1)) > > for most un*x machines. > -- > John Bass MOST UN*X machines?? Go suck a Honeywell !! (or A BBN) ==== ``Well, it works on all the machines I use'' is a great attitude if you can afford it: not everyone can (or wants to!). Even if you are willing to have your code break on a machine with one more bit, at least COMMENT the fact beforehand. ======= Also, if the the byte/word/long ... size is so important: WORK IT OUT !!!!!!!!!! ========================== How's this: bitsperword() { unsigned int i = ~0; int nbits = 0; do nbits++; while((i >>= 1) != 0); return nbits; } Yours portably, Dave Lukes