How does fread bring in a signed integer?
显示 更早的评论
Hello,
I am working with the reading in of binary files and I had a question on the fread function.
Basically, the datagram format specifies that the data samples are stored as signed 16bit integer (2's compliment). From looking around, there are a number of methods for handling signed numbers (2's compliment, 1's compliment, signed magnitude, offset...). So when i use fread() as follows:
s = fread(fid,256,'int16',0,'b');
Are the numbers read in as 2's compliment binary, or signed magnitude, or something else? I have to image it matters but I can't find what method MATLAB uses.
Thanks for any and all help!
1 个评论
Rik
2019-2-19
I couldn't find it in the doc either. IIRC almost everyone uses 2's complement, so I would assume Matlab does as well. You can read bit by bit if you want to make sure either way. There are only 2^16-1 numbers you need to check, which shouldn't take more than a few minutes to check.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!