Sir, I want to read fffd to '-3' not '65533'

6 views (last 30 days)
KiJun Baek
KiJun Baek on 23 Nov 2015
Answered: Image Analyst on 23 Nov 2015
I think I need to use a typecast. but I don't know how to use it.. I find inverse answer about my question.
sprintf('%x', typecast(int16(-3),'uint16'))
ans =
fffd
but I want to change fffd to -3 please help me sir..

Answers (1)

Image Analyst
Image Analyst on 23 Nov 2015
Try this:
theString = sprintf('%x', typecast(int16(-3),'uint16'))
negNumber = double(hex2dec(theString)) - double(intmax('uint16')) - 1;
fprintf('%s is %d in signed 16 bit integer\n', theString, negNumber);

Community Treasure Hunt

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

Start Hunting!