Main Content

storedInteger

Get stored integer value of fi object

Description

y = storedInteger(a) returns the stored integer value of fi object a. The stored integer y is returned as one of the built-in integer data types.

The real-world value of a fi object can be represented as

real-world value=(slope×stored integer)+bias

When the bias is zero and the slope is a power of two, commonly called binary-point scaling, this is often represented as

real-world value=2fraction length×stored integer

example

Examples

collapse all

This example shows how to use the storedInteger function to determine the stored integer values of two fi objects.

Define the fi object a using the default fixed-point data type.

a = fi([0.2 0.3 0.4 0.5]);
in_a = storedInteger(a)
in_a = 1×4 int16 row vector

    6554    9830   13107   16384

The stored integer values for fi object a are returned in the int16 data type because the fi constructor creates a fi object with a signed 16-bit data type by default.

Define the fi object a_nt using the fixed-point data type specified by the numerictype object nt.

nt = numerictype('WordLength',17);
a_nt = fi([0.2 0.3 0.4 0.5; 0.2 0.3 0.4 0.5],'numerictype',nt);
in_a_nt = storedInteger(a_nt)
in_a_nt = 2×4 int32 matrix

    6554    9830   13107   16384
    6554    9830   13107   16384

The stored integer values for fi object a_nt are returned in the int32 data type because this is the smallest built-in integer data type with at least 17 bits.

Input Arguments

collapse all

Fixed-point numeric object from which to get the stored integer value, specified as a scalar, vector, matrix, or multidimensional array fi object.

Data Types: fi
Complex Number Support: Yes

Output Arguments

collapse all

Stored integer value of input fi object a, returned as one of the built-in integer data types. The output has the same dimensions as the input. The data type of the output determined based on the signedness and word length (WL) of the stored integer:

Word Length of InputData Type of Output
WL ≤ 8 bitsint8 or uint8
8 bits < WL ≤ 16 bitsint16 or uint16
16 bits < WL ≤ 32 bitsint32 or uint32
32 bits < WL ≤ 64 bitsint64 or uint64

Data Types: int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Limitations

  • Integers greater than 64 bits are not supported by the storedInteger function. The storedInteger function errors when the data type of the output has 65 or more bits. For example,

    storedInteger(fi(1,0,65,0))
    
    Integers greater than 64 bits are not supported in 
    the 'storedInteger' function. For exact integer 
    representation for any word length, use BIN, OCT, 
    DEC, or HEX. To convert a stored integer value to 
    double for any word length, use storedIntegerToDouble.

Tips

  • For exact integer representation of any word length, use bin, dec, hex, oct, or sdec.

  • To convert a stored integer value to double precision for any word length, use the storedIntegerToDouble function.

Alternative Functionality

Function

The int and storedInteger functions both return the stored integer value of a fi object. You can use the int function to both get and set the stored integer of a fi object:

a = fi(pi);
y = int(a)  %get
y =

  int16

   25736
a = fi(pi);
a.int = 3;  %set
y = a.int   %get
y =

  int16

   3
You can use the storedInteger function only to get the stored integer value of a fi object.
a = fi(pi);
y = storedInteger(a) 
y =

  int16

   25736
The storedInteger function cannot be used to set the stored integer value of a fi object.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2012a

See Also

| | | | |