Converting HEX to uint8
36 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Patrik Ek
le 5 Fév 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'];
Réponse acceptée
Patrik Ek
le 5 Fév 2014
Modifié(e) : Patrik Ek
le 5 Fév 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!