¡@

Home 

c++ Programming Glossary: sub_wrap

Integer subtraction with wrap around for N bits

http://stackoverflow.com/questions/8309538/integer-subtraction-with-wrap-around-for-n-bits

way assuming a signed integer template int BITS int sub_wrap int v int s int max 1 BITS v s if v max v max 2 or if branching.. 24 from 16 with 5 bit wrap with a range of 32 31 sub_wrap 5 16 28 20 Is there a neat way of doing it that is less ugly.. and mask the results e.g. template int bits unsigned sub_wrap unsigned v unsigned s return v s 1 bits 1 More generally you..