Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site druxp.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!ihnp4!drutx!druxp!mab
From: mab@druxp.UUCP (BlandMA)
Newsgroups: net.lang.c
Subject: Re: How does one construct a mask for the MS bit?
Message-ID: <705@druxp.UUCP>
Date: Mon, 11-Mar-85 18:11:07 EST
Article-I.D.: druxp.705
Posted: Mon Mar 11 18:11:07 1985
Date-Received: Tue, 12-Mar-85 09:48:31 EST
References: <8849@brl-tgr.ARPA> <169@dmsd.UUCP> <455@harvard.ARPA>
Organization: AT&T Information Systems Laboratories, Denver
Lines: 27

John Bass in article <169@dmsd.UUCP> recommends:
>	#define MSB(a)		(1<<((sizeof a) * 8 - 1))

Stew Rubenstein in article <455@harvard.ARPA> replies:
>	Is it portable to assume 8 bit bytes?  Answer:  no....

If you're running UNIX System V (and possibly other UNIX systems, I don't
know), take a look at /usr/include/values.h, which defines a number of
constants that might be of use, such as:

	BITSPERBYTE  number of bits in a byte
	HIBITS       bit mask for the high bit of a short
	HIBITI       ditto for int
	HIBITL       ditto for long
	MAXSHORT     maximum value of a signed short
	MAXINT       ditto for int
	MAXLONG      ditto for long

HIBITS, HIBITI, and HIBITL are macros defined in terms of BITSPERBYTE
using the same formula that John Bass gave.  BITSPERBYTE is conditionally
compiled using #if.

UNIX is a trademark of AT&T Bell Laboratories.
-- 
Alan Bland
{ihnp4, allegra}!druxp!mab
AT&T Information Systems Labs, Denver