How to convert char to uint8 and vice versa without changing the underlying data
27 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
.
0 Kommentare
Antworten (2)
James Tursa
am 4 Feb. 2020
Bearbeitet: James Tursa
am 4 Feb. 2020
Simply:
c = original char array
u = uint8(c);
Or
u = original uint8 array
c = char(u);
If you mean you want to reinterpret one as the other without a data copy, you can't because MATLAB stores char data as 2-bytes per char and uint8 is of course 1 byte per element.
If you want to reinterpret the char as uint16 or vice-versa without a data copy, it can be done but not officially. You have to resort to mex hacks. E.g.,
0 Kommentare
Walter Roberson
am 4 Feb. 2020
I speculate that what you need is https://www.mathworks.com/help/matlab/ref/unicode2native.html unicode2native() to convert characters to bytes, and native2unicode() to convert bytes to unicode. The functions offer a variety of ways of encoding character positions greater than 255, including UTF8 and UTF16LE and UTF16BE .
0 Kommentare
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!