Re: C macro to find the next power of 2 ?

From: Jens Schweikhardt <schweikh_at_schweikhardt.net>
Date: Thu, 8 Feb 2007 23:24:44 +0100
Luigi,

...
# 
# But i was wondering if there is some simpler code which
# can still be computed as a compile-time constant?

Is this requirement non-negotiable? Maybe in the days of C99
and run-time sized arrays it's worth thinking about other solutions
than CPP magic.

For this and other bit twiddling hacks in C (mostly functional), see
http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2

Regards,

	Jens
-- 
Jens Schweikhardt http://www.schweikhardt.net/
SIGSIG -- signature too long (core dumped)
Received on Thu Feb 08 2007 - 22:08:57 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:05 UTC