From: Eric S. Raymond Date: Fri, 2 Jun 2017 20:40:29 +0000 (-0400) Subject: Simplify bitmask test/set from FORTRANish to actual C. X-Git-Tag: 0.90~28 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=aef609291dd382447c9edbe7717d127485a9ab4f;p=open-adventure.git Simplify bitmask test/set from FORTRANish to actual C. --- diff --git a/advent.h b/advent.h index 074836c..631cce2 100644 --- a/advent.h +++ b/advent.h @@ -55,7 +55,7 @@ extern void CARRY(long,long); extern void DROP(long,long); extern long ATDWRF(long); extern long SETBIT(long); -extern long TSTBIT(long,long); +extern bool TSTBIT(long,int); extern long RNDVOC(long,long); extern void BUG(long); extern void MAPLIN(FILE *); diff --git a/misc.c b/misc.c index 365d7c8..7dfa742 100644 --- a/misc.c +++ b/misc.c @@ -631,26 +631,14 @@ L2: AT=I; /* Utility routines (SETBIT, TSTBIT, set_seed, get_next_lcg_value, * randrange, RNDVOC, BUG) */ -long SETBIT(long BIT) { -long I, IND; - +long SETBIT(long bit) { /* Returns 2**bit for use in constructing bit-masks. */ - - IND=1; - if(BIT <= 0)return(IND); - for (I=1; I<=BIT; I++) { - IND=IND+IND; - } /* end loop */ - return(IND); + 2 << bit; } - - -long TSTBIT(long MASK, long BIT) { - +bool TSTBIT(long mask, int bit) { /* Returns true if the specified bit is set in the mask. */ - - return(MOD(MASK/SETBIT(BIT),2) != 0); + return((mask & (1 << bit)) != 0); } void set_seed(long seedval)