Quantcast
Channel: User Alex Lop. - Stack Overflow
Viewing all articles
Browse latest Browse all 39

Answer by Alex Lop. for Is there a better way to mask bits?

$
0
0

For your specific example you can use:

if ((bits != 12 && bits != 16) || addressSize != 32) {    isValid = false;    printf("Invalid!");} else {    offsetMask = (1u << bits) - 1;}

However it depends what you mean by "better".There are many different aspects like memory footprint, performance, readability.

I think the code in the question is more readable but probably less efficient than the one I proposed.


Viewing all articles
Browse latest Browse all 39

Trending Articles