c++ - What is the difference between -1 and ~0 -
c++ - What is the difference between -1 and ~0 -
the title says all: difference between minus 1 , tilda (ones-complement) zero?
the question came during give-and-take of best way specify bit mask in bits set. of next better?
int func(int value, int mask = -1) { homecoming (value & mask); } or
int func(int value, int mask = ~0) { homecoming (value & mask); } are there other uses other way around?
update: there has been similar give-and-take on topic on @ stackoverflow.com/q/809227/34509 missed during prior research. johannes schaub pointing out.
the first variant relies on 2's complement representation of negative numbers, isn't used. 1's complement can used too... or other encoding. vote sec approach
c++ bitmask ones-complement
Comments
Post a Comment