convert 16bit char to 4 byte hex values

I have an length X 16 variable of type char. i'd like to convert it to length x 4 nibble hex values
example input: char(3x16)
1000100010001000
0000000000000010
111111111111111111
output wanted 8888
0002
FFFF

1 件のコメント

Darin Liberda
Darin Liberda 2023 年 6 月 27 日
sorry 4 nibbles i guess that would be

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

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2023 年 6 月 27 日

0 投票

c=char(["1000100010001000";
"0000000000000010";
"1111111111111111"])
c = 3×16 char array
'1000100010001000' '0000000000000010' '1111111111111111'
d=dec2hex(bin2dec(c))
d = 3×4 char array
'8888' '0002' 'FFFF'

4 件のコメント

Darin Liberda
Darin Liberda 2023 年 6 月 27 日
Very nice and simple! thank you. i have been trying every conversion function in the book and thought it would take a double to work.
Fangjun Jiang
Fangjun Jiang 2023 年 6 月 27 日
I thought there should be a bin2hex() function but didn't find it. Maybe someone else can suggest a direct conversion method?
Fangjun Jiang
Fangjun Jiang 2023 年 6 月 27 日
If your original data is not constrained to be char array, maybe take a look at this document
Nathan Hardenberg
Nathan Hardenberg 2023 年 7 月 11 日
There is a custom bin2hex()-function on File Exchange

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

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

タグ

質問済み:

2023 年 6 月 27 日

コメント済み:

2023 年 7 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by