Conversion from uint8 to ascii to number
24 ビュー (過去 30 日間)
古いコメントを表示
I am currently working with RS232 serial communication between a Trimble gps and a Speedgoat real time computer in Simulink. From the buffer in the Speedgoat i receive a uint8 array, that i want to convert to a the corresponding ascii value and then convert the new array into one double.
For example
uint8: [48 46 56 52] -> [0 . 8 4] -> 0.84
Help would be much appreciated!
2 件のコメント
Zhengyi Chen
2019 年 4 月 11 日
You can convert uin8 data into char and use str2double() function to conver the strings in to double data type.
回答 (3 件)
José-Luis
2012 年 10 月 24 日
Somewhat convoluted, depends on whether you can use sprintf() and sscanf():
your_ascii = [48 46 56 52];
your_ascii = your_ascii - '0';
your_string = sprintf('%i',your_ascii);
% your_string = regexprep(your_string,'-','.'); %This could work also, instead of the indexing
your_string(your_string == '-') = '.';
your_val = sscanf(your_string,'%f');
0 件のコメント
Andrei Bobrov
2012 年 10 月 24 日
a = uint8([50 48 46 48 48 56 52] );
i0 = a == 46;
a1 = a(~i0)-'0';
out = double(a1)*(10.^(numel(a1)-1:-1:0).')*10^-(find(i0)+1);