フィルターのクリア

uint16 to uint8

124 ビュー (過去 30 日間)
Svyatoslav Kharitonov
Svyatoslav Kharitonov 2019 年 7 月 30 日
コメント済み: Walter Roberson 2022 年 2 月 27 日
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!

採用された回答

James Tursa
James Tursa 2019 年 7 月 30 日
u16 = your uint16 variable
u8 = typecast(u16,'uint8');
  1 件のコメント
Svyatoslav Kharitonov
Svyatoslav Kharitonov 2019 年 7 月 30 日
Great! Thank you very much!

サインインしてコメントする。

その他の回答 (1 件)

Hiral Padhariya
Hiral Padhariya 2022 年 2 月 27 日
u8 = typecast(u16,'uint8');
  1 件のコメント
Walter Roberson
Walter Roberson 2022 年 2 月 27 日
What difference do you perceive between your answer and what James posted 2 1/2 years ago?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by