Main Content

nextpow2

Exponent of next higher power of 2 of fi object

Description

example

P = nextpow2(N) returns the first P such that 2.^P >= abs(N). By convention, nextpow2(0) returns zero.

Examples

collapse all

Define a fi object and calculate the exponent for the next higher power of 2.

N = fi(1000,1,18,2);
P = nextpow2(N)
P = 

    10

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 6
        FractionLength: 0

Define a vector of fi values and calculate the exponents for the next power of 2 higher than those values.

N = fi([1 -2 3 -4 5 9 519],1,16,3,2);
P = nextpow2(N)
P = 

     1     0     1     2     3     3    10

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Unsigned
            WordLength: 5
        FractionLength: 0

Input Arguments

collapse all

Input values, specified as a real-valued scalar, vector, or N-dimensional array.

Data Types: fi

Output Arguments

collapse all

Exponent of next higher power of 2, returned as a scalar, vector, or N-dimensional array.

The output is returned as an unsigned fi object with binary-point scaling, a fraction length of zero, and the smallest word length which can represent the value of the largest returned exponent.

Extended Capabilities

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

See Also

|

Introduced in R2020a