Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
1 rating:
 1 out of 5     Rate this Document

Ceiling to the Nearest Power of 2?

Primary Software: LabWindows/CVI Run-Time Engine
Primary Software Version: 7.0
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem: In C, how can I round a number to the nearest power of 2, greater or equal to the entered value?

Solution:

/* The variable "value" is the user entered number. */
static ViInt32 CoerceToPower2 ( ViInt32 value )
{
ViInt32 i;
for(i = 0; i < value; i <<= 1);
return i;
}


Related Links:

Attachments:





Report Date: 10/13/1999
Last Updated: 05/28/2004
Document ID: 1QCAG1EE

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit