# is there any function to convert uint to uchar?

11 visualizaciones (últimos 30 días)
jimy george el 6 de En. de 2014
Editada: Stephen23 el 28 de Feb. de 2023
is it possible to convert unsigned integer to unsigned character?
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Amith el 28 de Feb. de 2023
Editada: Amith el 28 de Feb. de 2023
As per my understanding you wanted to convert unsigned integer to unsigned character .It is possible to convert an unsigned integer to an unsigned character.
You can use unit8 function to convert the integer to an unsigned 8 bit integer, which is equivalent to an unsigned character. This can also be type casted to char using ‘char’ . The below code demonstrated it -
% Define an unsigned integer
x = uint32(123);
% Convert the unsigned integer to an unsigned character
y = uint8(x);
%or
z = char(x);
% Display the results
fprintf('Unsigned integer: %u\n', x);
fprintf('Unsigned character: %c\n', z);
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Stephen23 el 28 de Feb. de 2023
Editada: Stephen23 el 28 de Feb. de 2023
Why convert to UINT8? There is absolutely no problem using UINT32 directly:
x = uint32(123);
char(x)
ans = '{'
The MATLAB documentation recommends "if you need to store the numeric values as integers, use unsigned integers having at least 16 bits because MATLAB uses the UTF-16 encoding."

Iniciar sesión para comentar.

### Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by