Effacer les filtres
Effacer les filtres

uint16 to uint8

124 vues (au cours des 30 derniers jours)
Svyatoslav Kharitonov
Svyatoslav Kharitonov le 30 Juil 2019
Commenté : Walter Roberson le 27 Fév 2022
Dear all,
I wonder whether there is an efficient way of converting an uint16 array of length N in an uint8 array of length 2N, so essentially replacing every 16bit word with two bytes:
e.g.
15000 => 58, 152
11000 => 42, 248.
The simplest implementation would be to convert decimal to binary string with 16 elements, and then split them 1..8 and 9...16, but I wonder if we can do another way.
Thank you in advance!

Réponse acceptée

James Tursa
James Tursa le 30 Juil 2019
u16 = your uint16 variable
u8 = typecast(u16,'uint8');
  1 commentaire
Svyatoslav Kharitonov
Svyatoslav Kharitonov le 30 Juil 2019
Great! Thank you very much!

Connectez-vous pour commenter.

Plus de réponses (1)

Hiral Padhariya
Hiral Padhariya le 27 Fév 2022
u8 = typecast(u16,'uint8');
  1 commentaire
Walter Roberson
Walter Roberson le 27 Fév 2022
What difference do you perceive between your answer and what James posted 2 1/2 years ago?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings 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!

Translated by