How does one construct a mask for the MS bit?

Dave Lukes dave at inset.UUCP
Thu Mar 21 03:49:07 AEST 1985


Newsgroups: net.lang.c
Subject: Re: How does one construct a mask for the MS bit?
References: <8849 at brl-tgr.ARPA>, <169 at 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



More information about the Comp.lang.c mailing list