MATLAB: Converting HEX to uint8

hex2decoverflowserial deviceuint8unit8

Hello I want to convert a very long HEX-String into the uint 8 format because i want so send the uint8 signal through an RS-232 device.
The first step i did, was converting the HEX-String in a decimal number with the hex2dec('HEX-String'. After that i used the uint8 ('previousresult').
My Problem is, that the HEX-String is too long and results in a decimal number of about 1*10^93 this leads to an data-overload.
Can anyone help me?
Thanks a lot!
Greetings

Best Answer

Try to reshape it first. You of course only want to send in 2hex at a time since the largest unit8 is 255. Try this,
hexstring = 'aabbccddee';
reshapedString = reshape(hexstring,2,5);
hexMtx = reshapedString.';
disp(hexMtx);
decMtx = hex2dec(hexMtx);
disp(decMtx);
intVector = uint8(decMtx);
disp(intVector);
This will give you an uint8 column vector. If you want it as a string format (the uint8 vector) then do,
intString = num2str(intVector');
intString = strrep(intString,' ','');
Good luck and comment if questions.
Related Question