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!