Using int64 for changing the data class
Mostrar comentarios más antiguos
When using the int64 function on a 32-bit set of data. Does this just add the appropriate number of zeros into the end of the packets of data?
I have read the documentation, and just wanted to confirm that this works the same way as, single to double.
I don't have code to provide as this is a general question, thanks in advance for any help.
Respuesta aceptada
Más respuestas (1)
Steven Lord
el 5 de Dic. de 2018
Using int64 to convert a value stored in another type converts the value into the corresponding int64 value (with saturation or rounding if necessary.) In the example below, y has the same values as x but a different type.
If you want to reinterpret the bit pattern, that's a job for typecast. [Depending on how you plan to use the result, you may also need or want to use swapbytes.] In the example below z does not have the same values as x, but is a combination of the bit patterns of x.
Note that z, the result of typecast, is half the length of x. Two int32 values have enough bytes to make one int64.
>> x = int32([4 8 15 16 23 42])
x =
1×6 int32 row vector
4 8 15 16 23 42
>> y = int64(x)
y =
1×6 int64 row vector
4 8 15 16 23 42
>> z = typecast(x, 'int64')
z =
1×3 int64 row vector
34359738372 68719476751 180388626455
You can see the difference if you look at the three variables using format hex.
>> format hex
>> x, y, z
x =
1×6 int32 row vector
00000004 00000008 0000000f 00000010 00000017 0000002a
y =
1×6 int64 row vector
0000000000000004 0000000000000008 000000000000000f 0000000000000010 0000000000000017 000000000000002a
z =
1×3 int64 row vector
0000000800000004 000000100000000f 0000002a00000017
Reset to the default format before you forget.
>> format
There's one other function that I want to mention: cast converts value not bit pattern.
1 comentario
James Best
el 6 de Dic. de 2018
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!