sticking together 4 hex bytes question

Hello I have four DECIMAL numer for example 31(1F) 47(2F) 63(3F) FF(255)
how using those decimal numbers i get a HEX number of 1F2F3FFF?
Thanks.

回答 (2 件)

Ameer Hamza
Ameer Hamza 2020 年 11 月 1 日
編集済み: Ameer Hamza 2020 年 11 月 1 日

0 投票

Try this code
x = [31 47 63 255];
y = reshape(dec2hex(x).', 1, [])
Result
>> y
y =
'1F2F3FFF'

6 件のコメント

fima v
fima v 2020 年 11 月 1 日
Hello Ameer, you are transposing the vector to be vertical from horisontal.
what is the meaning of reshaping 1,[] ?
Thanks.
Ameer Hamza
Ameer Hamza 2020 年 11 月 1 日
Just to make it a row vector. The output without it is
>> x = [31 47 63 255];
>> dec2hex(x).'
ans =
2×4 char array
'123F'
'FFFF'
fima v
fima v 2020 年 11 月 1 日
編集済み: fima v 2020 年 11 月 1 日
Hello Ameer,Yes that i understood, after you created a row vector.
we have another line of reshaping 1,[]
what is the meaning of it?
Ameer Hamza
Ameer Hamza 2020 年 11 月 1 日
reshape(dec2hex(x).', 1, []) means that take the output of dec2hex(x).' and convert it into a vector with one row.
fima v
fima v 2020 年 11 月 1 日
編集済み: fima v 2020 年 11 月 1 日
but X was a row vector in the beginning :-)
How its different now?
maybe it means make row vector with one column? that will explain wjy we get one number 1X1 vector.
Thanks.
Ameer Hamza
Ameer Hamza 2020 年 11 月 1 日
I think it is better you run the following lines one by one. Then you will get an idea of what is happening
x = [31 47 63 255];
y = dec2hex(x)
y = y.'
y = reshape(y, 1, [])

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

Walter Roberson
Walter Roberson 2020 年 11 月 1 日

0 投票

x = [31 47 63 255];
swap(typecast(uint8(x), 'uint64'))

3 件のコメント

Ameer Hamza
Ameer Hamza 2020 年 11 月 1 日
I think that the second line should be
dec2hex(swapbytes(typecast(uint8(x), 'uint32')))
or also this
dec2hex(typecast(uint8(fliplr(x)), 'uint32'))
Walter Roberson
Walter Roberson 2020 年 11 月 1 日
ah yes you are right, swapbytes and uint32
fima v
fima v 2020 年 11 月 1 日
編集済み: fima v 2020 年 11 月 1 日
Hello Walter, can i please have intuition for the line Ameer posted?
first you take my array and convert each member from uint8 to uint32 are you dound zero padding?
then in each member you swap its numbers ,Why?
Then you convert each member from decimal to hex ,but our number is not decimal its uint_32
and we still have an array,how it came to be only one number?
Thanks.

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

カテゴリ

タグ

質問済み:

2020 年 11 月 1 日

コメント済み:

2020 年 11 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by