Main Content

int

Get and set stored integer value of fi object

Description

y = int(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 int function to get and set the stored integer values fi objects.

Create fi object a using the default settings. Use the int function to get the stored integer value of the fi object.

a = fi(pi);
int_a = int(a)
int_a = int16

25736

The output is returned as an int16 because the input used the default 16-bit word length.

Create fi object b that uses a 20-bit word length. Use the int function to get the stored integer value of the fi object.

b = fi(pi,1,20);
int_b = int(b)
int_b = int32

411775

The output is returned as an int32 to accommodate the larger input word length.

Create fi object c that uses an 8-bit word length. Use the int function to get the stored integer value of the fi object. Then use the int function to set the stored integer value of fi object c to 6.

c = fi(pi,1,8);
c_int = c.int
c_int = int8

101
c.int = 6
c = 
    0.1875

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 8
        FractionLength: 5

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

  • When you use the int function to get a stored integer value that is greater than 64 bits, the int function casts the output to double precision. This may result in round-off error. For exact integer representation of any word length, use bin, dec, hex, oct, or sdec.

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.

Version History

Introduced in R2006a

See Also

| | | | |