functions to combine two hexadecimal numbers
18 次查看(过去 30 天)
显示 更早的评论
I'm doing a project that involves taking in data from an EMG, running it through a function in Matlab, and sending commands to a series of motors. The motors take a series of 2 hex numbers, one 2 digits, one 4 digits preceded by the letter d. For example, d0103FF. My question is, how can I write a series of functions that takes the difference between two numbers, converts it to a zero padded four digit hexadecimal, and then tacks it onto the end of dXX where X is another number.
2 个评论
Chaowei Chen
2011-9-25
can you give an example about the I/O? If the format is regular, my approach would be to treat d0103FF as a string and read it digit by digit
采纳的回答
Rick Rosson
2011-9-25
y = desired - actual;
h2 = dec2hex(x,2);
h4 = dec2hex(y,4);
out = [ 'd' h2 h4 ];
0 个评论
更多回答(2 个)
Jan
2011-9-25
SPRINTF('%x') and the corresponding FPRINTF commands are very fast for the conversion of hexadecimal and decimal numbers - mucgh faster than HEX2DEC and DEC2HEX:
out = sprintf('d%.2x%.4x', x, y)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specialized Power Systems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!