Main Content

int64

64-bit signed integer arrays

Description

Variables in MATLAB® of data type (class) int64 are stored as 8-byte (64-bit) signed integers. For example:

y = int64(10);
whos y
  Name      Size            Bytes  Class    Attributes

  y         1x1                 8  int64                    

For more information on integer types, see Integers.

Creation

Some array creation functions allow you to specify the data type. For instance, zeros(100,'int64') creates a 100-by-100 matrix of zeros of type int64.

If you have an array of a different type, such as double or single, then you can convert that array to an array of type int64 by using the int64 function.

Description

Y = int64(X) converts the values in X to type int64. Values outside the range [–263, 263–1] map to the nearest endpoint.

example

Input Arguments

expand all

Input array, specified as a scalar, vector, matrix, or multidimensional array.

Data Types: double | single | int8 | int16 | int32 | uint8 | uint16 | uint32 | uint64 | logical | char

Examples

collapse all

Convert a double-precision variable to a 64-bit signed integer.

x = 100;
xtype = class(x)
xtype = 
'double'
y = int64(x)
y = int64

100

Convert an array of large integers (larger than flintmax) to a 64-bit signed integer array. When you specify a numeric array input, precision can be lost because MATLAB initially represents the input as double precision by default.

Y_inaccurate = int64([-72057594035891654 81997179153022975])
Y_inaccurate = 1x2 int64 row vector

   -72057594035891656    81997179153022976

To maintain precision when creating a 64-bit signed integer array, call int64 with each scalar element instead.

Y_accurate = [int64(-72057594035891654) int64(81997179153022975)]
Y_accurate = 1x2 int64 row vector

   -72057594035891654    81997179153022975

Starting in R2019b, you can also create the integer array accurately by using the hexadecimal or binary values of the integers. For more information, see Hexadecimal and Binary Values.

Y_accurate = [0xFF000000001F123As64 0x1234FFFFFFFFFFFs64]
Y_accurate = 1x2 int64 row vector

   -72057594035891654    81997179153022975

Tips

  • When you create a numeric array of large integers (larger than flintmax), MATLAB initially represents the input as double precision by default. Precision can be lost when you convert this input to the int64 data type. To maintain precision, call int64 with each scalar element of the array instead. For example, see Convert Array of Large Integers Without Loss of Precision.

  • If you have text formatted in a character array or string scalar that contains large integers, then you can read this text and return an accurate 64-bit signed integer array by using the sscanf function. You can specify the format of the input fields so that sscanf directly converts the text that represents integers in decimals, octals, or hexadecimals without first converting them to Unicode code values. For comparison, int64(X) converts a character vector input to an integer array that represents the Unicode code values for each character.

Extended Capabilities

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

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Version History

Introduced before R2006a