How are uint8 calculated? And how can I convert them back to Integers in Codesys?
Mostrar comentarios más antiguos
I am converting a Struct containing integers to a uint8
data = struct('Header', [], 'Pos', []);
data.Header = 1010;
data.Pos = double([81, -17, 8651]);
uintHeader = typecast(data.Header, 'uint8');
uintPos = typecast(data.Pos, 'uint8');
dataArray = [uintHeader uintPos];
dataArray = 0 0 0 0 0 144 143 64 0 0 0 0 0 64 84 64 0 0 0 0 0 0 49 192 0 0 0 0 128 229 192 64
How do i get from '1010' to '0 0 0 0 0 144 143 64' etc.?
I then send this array to a system that runs on Codesys.
Is there a function in Codesys, which can convert it back to the original integers?
3 comentarios
Is data.Header supposed to be 1010 or 0b1010?
A = 1010; % A is a 64b float
typecast(A,'uint8') % take all 64 bits and split them up into 8-bit blocks
B = '1010'; % B is a string representation of a binary word
uint8(bin2dec(B))
Tim
el 20 de Dic. de 2023
Since 'Header' is a 64 bit float number the representation in hexadecimal format is
format hex
1010
and each byte in ascending order
format short
uint8([0x0 0x0 0x0 0x0 0x0 0x90 0x8f 0x40])
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Data Type Conversion 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!