Converting HEX to uint8
36 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
1 Kommentar
Patrik Ek
am 5 Feb. 2014
You may want to split up the string into smaller parts. the largest uint8 allowed is 255 (which you probably knew). What you want to have then is something on a format,
original = 'aabbccdd';
wanted = ['aa';'bb';'cc';'dd'];
Akzeptierte Antwort
Patrik Ek
am 5 Feb. 2014
Bearbeitet: Patrik Ek
am 5 Feb. 2014
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!