Better way to generate a mask?
Francois Pinard
pinard at IRO.UMontreal.CA
Wed May 29 04:03:59 AEST 1991
I just thought asking to the net. Which of the following is better?
And of course, why?
---------------------------------------------------------------------->
/* This macro generates a mask of NUMBER one bits, right adjusted. */
#define MASK(number) \
(~(~0 << (number)))
----------------------------------------------------------------------<
---------------------------------------------------------------------->
/* This macro generates a mask of NUMBER one bits, right adjusted. */
#define MASK(number) \
((1 << (number)) - 1)
----------------------------------------------------------------------<
--
Franc,ois Pinard ``Vivement GNU!'' pinard at iro.umontreal.ca
(514) 588-4656 cp 886 L'Epiphanie (Qc) J0K 1J0 ...!uunet!iros1!pinard
More information about the Comp.lang.c
mailing list