How to get two 16-bit numbers from a 32bit number

조회 수: 25 (최근 30일)
Dharmesh Joshi
Dharmesh Joshi 2022년 8월 16일
댓글: James Tursa 2022년 8월 16일
HI
I have 32-bit variable.
I would like to split this into two 16-bit numbers, How can i do this?

답변 (1개)

James Tursa
James Tursa 2022년 8월 16일
편집: James Tursa 2022년 8월 16일
E.g., to split a uint32 into two uint16 you can use typecast( ):
result = typecast(your_variable,'uint16')
This result will contain the original bit pattern of the input variable.
  댓글 수: 2
Dharmesh Joshi
Dharmesh Joshi 2022년 8월 16일
What about if you have an array for uint32?
It seems typecast places all 16-bits into one array.
James Tursa
James Tursa 2022년 8월 16일
Yes. typecast( ) simply re-interprets all of the 32-bit patterns as 16-bit patterns as they appear in memory. So an array input will result in an array output with twice as many elements. Is this not what you want? If you want something different you will have to give a short example of input and desired output.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by