How does one construct a mask for the MS bit?

cottrell at NBS-VMS.ARPA cottrell at NBS-VMS.ARPA
Sat Mar 2 09:53:53 AEST 1985


/*
> This would require generation of a mask for the most significant bit

int msbit()
{	register int msb = 1;
	while ((msb <<= 1) > 0);
	return(msb);
}

I am assuming that the msb is used as the sign bit. If that's not 
portable, then shift until msb is zero, counting the shifts. Then
return(1 << --count). (I am also assuming an int is more than one bit :-)

	jim
*/



More information about the Comp.lang.c mailing list