how the function typecast works when convert double to uint8

조회 수: 5 (최근 30일)
Yucheng Fu
Yucheng Fu 2015년 8월 31일
댓글: Yucheng Fu 2015년 9월 2일
I test the function typecast as follows:
z=double(1);
z1=typecast(z,'uint8');
and the results shows the
z1 = 0 0 0 0 0 0 240 63
As to my knowledge, each element in z1 should represent one 8-bit unsigned number. But the sum is not equal to 1.
Does anyone know how the function works and what's the meaning in vector z1?

채택된 답변

Cedric
Cedric 2015년 8월 31일
편집: Cedric 2015년 8월 31일
Look at the difference between CAST and TYPECAST, and you will understand what happens in your example.
PS: if you want to understand where these 240(F0) and 63(3F) come from, have a look a this wiki.
  댓글 수: 1
Yucheng Fu
Yucheng Fu 2015년 9월 2일
Thank you for the help. The double format has 64 bit length. This explains exactly what happens to my case. When the typecast convert it to uint8, it should have 8 separate numbers.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by