How to convert data byte by byte
이전 댓글 표시
I have read a file and data im getting is shown below. I have to convert this data byte by byte in decimal number please tell me how can I do that ?

댓글 수: 2
Jan
2021년 1월 27일
Typing an answer would be easier, if the file or its contents is provided as text.
채택된 답변
추가 답변 (3개)
David Hill
2021년 1월 27일
d=hex2dec(regexp(a,'[0-9a-f]+','match'));
s = '|0|01|00|5e|'
data = split(s, '|')
d = hex2dec(data)
If you want to eliminate the first and last 0 in d, trim the leading and trailing | characters from s before splitting.
Jan
2021년 1월 27일
A comparison of the runtimes:
s = repmat('|0|01|00|5e', 1, 2000);
tic
for k = 1:100
d = hex2dec(regexp(s, '[0-9a-f]+', 'match'));
end
toc
tic
for k = 1:100
d = hex2dec(split(s, '|'));
end
toc
tic
for k = 1:100
d = sscanf(s, '|%x');
end
toc
tic
for k = 1:100
d = sscanf(strrep(s, '|', ' '), '%x');
end
toc
% Elapsed time is 0.909770 seconds.
% Elapsed time is 0.424414 seconds.
% Elapsed time is 0.272269 seconds.
% Elapsed time is 0.163054 seconds.
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!