sticking together 4 hex bytes question

2 views (last 30 days)
fima v on 1 Nov 2020
Commented: Ameer Hamza on 1 Nov 2020
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.

Ameer Hamza on 1 Nov 2020
Edited: Ameer Hamza on 1 Nov 2020
Try this code
x = [31 47 63 255];
y = reshape(dec2hex(x).', 1, [])
Result
>> y
y =
'1F2F3FFF'
Ameer Hamza on 1 Nov 2020
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 on 1 Nov 2020
x = [31 47 63 255];
swap(typecast(uint8(x), 'uint64'))
fima v on 1 Nov 2020
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.