converting binary to decimal

i have a value as S=-5
i converted it to binary by
Cw1=dec2bin(typecast(int16(S),'uint16'),15)
now how to convert again to -5
plz assist

 채택된 답변

Image Analyst
Image Analyst 2013년 1월 19일

0 개 추천

Why are you using uint16 when you have a negative number?????
Anyway,...
S = -5;
Cw1=dec2bin(typecast(int16(S),'uint16'),15)
S_recovered = bin2dec(Cw1)
maxUint16 = intmax('uint16')
maxInt16 = intmax('int16')
if S_recovered > maxInt16
S_recovered = int16(S_recovered - double(maxUint16) - 1)
end
S_recovered will be -5 as a signed 16 bit integer, which is what I assume you want.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 1월 19일

0 개 추천

typecast(bin2dec(Cw1), 'int16')

댓글 수: 2

FIR
FIR 2013년 1월 21일
Walter i get
typecast(bin2dec(Cw1), 'int16')
ans =
0 0 -160 16623
typecast(uint16(bin2dec(Cw1)),'int16')

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

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

질문:

FIR
2013년 1월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by