ASCII to HEX conversion problem
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I'm trying to convert the ASCII data that I read from a file to HEX. now my problem is that, althogh my data is 8 ASCII characters, but when convert it using:
rawdata = readtable(filename,opts); % read data from file
rawarr = table2array(rawdata);
asc = regexp(rawarr(2,1),'"','split');
asc = asc{1};
AsciiText = cell2mat(asc(1));
hexValue = sprintf('%02X', AsciiText);
A = typecast(uint32(hex2dec([hexValue(9:end);hexValue(1:8)])), 'uint64'); % here i need exactly 1x16 char.
% I have also used A = hex2num(hexValue) instead of the last line. But the result is not correct.
sometimes the result is 1x16 char (which is correct) but sometimes it becomes 1x18 (first data in first line) or 1x20 (first data in second line). When I read the file with Hexeditor, I see that all the characters have been converted correctly and just one of the is converted to more than two chars.
as an example: when I convert T5‚õy to HEX I receive: '205435201AF5187908' although it should be '20543582F5187908'.
why it does not convert each ASCII character into two character HEX? Is there any problem with some special ASCII characters? and finally is there any safe way to do this conversion to receive exaclty 2 hex chars for each one ASCII chararcter?
I appreciate to see your comments.
0 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Data Type Conversion in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!