electroRF
Member
Hi,
Say that you got a number N, and you want it to be dividable by other number M, and you know that M is a power of 2.
For example, N = 123, M = 64.
I'm trying to write an efficient C code to find the minimal number that is larger than N and is dividable by M.
in this case -> 128
I made a few tests and the following seems to work:
( N + (M-1) ) & ~(M-1)
you see any problem with that?
anything more efficient that that?
Thank you.
Say that you got a number N, and you want it to be dividable by other number M, and you know that M is a power of 2.
For example, N = 123, M = 64.
I'm trying to write an efficient C code to find the minimal number that is larger than N and is dividable by M.
in this case -> 128
I made a few tests and the following seems to work:
( N + (M-1) ) & ~(M-1)
you see any problem with that?
anything more efficient that that?
Thank you.