converting binary to decimal
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Image Analyst
2013-1-19
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.
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!