How are uint8 calculated? And how can I convert them back to Integers in Codesys?
이전 댓글 표시
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
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
2023년 12월 20일
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])
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!