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
2020년 11월 1일
편집: Ameer Hamza
2020년 11월 1일
Try this code
x = [31 47 63 255];
y = reshape(dec2hex(x).', 1, [])
Result
>> y
y =
'1F2F3FFF'
댓글 수: 6
fima v
2020년 11월 1일
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'
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.
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
2020년 11월 1일
x = [31 47 63 255];
swap(typecast(uint8(x), 'uint64'))
댓글 수: 3
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
2020년 11월 1일
ah yes you are right, swapbytes and uint32
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!