필터 지우기
필터 지우기

Is there a way to read 16bit float(mantissa 8bit)bin file?

조회 수: 5 (최근 30일)
Won Geun Shin
Won Geun Shin 2022년 9월 2일
편집: James Tursa 2022년 9월 7일
I've found a function CustomFloat but I can't find a way to read the file...
it goes like this
00 00 07 00 F8 FF FD FF 01 00 01 00 01 00 FF FF
  댓글 수: 8
Won Geun Shin
Won Geun Shin 2022년 9월 7일
so I guess I can use bin2num function to covert that..
Thanks a lot
James Tursa
James Tursa 2022년 9월 7일
편집: James Tursa 2022년 9월 7일
@Walter Roberson Would also need to know whether the significand is normalized to 1.0 binary or 0.1 binary. This ties in with the exponent bias, of course.

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

채택된 답변

Walter Roberson
Walter Roberson 2022년 9월 7일
str = "00 00 07 00 F8 FF FD FF 01 00 01 00 01 00 FF FF 46 C0 B9 40"
str = "00 00 07 00 F8 FF FD FF 01 00 01 00 01 00 FF FF 46 C0 B9 40"
A = sscanf(str, "%2x", [1 inf]);
if mod(numel(A), 2) == 1; A(end+1) = 0; end %pad if odd length
MSB = A(1:2:end);
mask = MSB >= 128;
MSB(mask) = MSB(mask) - 256;
LSB = A(2:2:end);
out = MSB + LSB/256;
format long g
out.'
ans = 10×1
0 7 -7.00390625 -2.00390625 1 1 1 -0.00390625 70.75 -70.75

추가 답변 (1개)

Chunru
Chunru 2022년 9월 5일
str = "00 00 07 00 F8 FF FD FF 01 00 01 00 01 00 FF FF"
str = "00 00 07 00 F8 FF FD FF 01 00 01 00 01 00 FF FF"
a = sscanf(str, "%s%s", inf);
n = floor(length(a)/4)
n = 8
afi = fi(0, 1, 16, 7); % signed, 16-bit word, 7-bit fraction
for i=1:n
h = a((i-1)*4 + (1:4)); % the hex from data input
afi.hex = h; % assign the hex to fi
d = afi.double; % convert to double
fprintf("%s : %f\n", afi.hex, afi.double)
end
0000 : 0.000000 0700 : 14.000000 f8ff : -14.007812 fdff : -4.007812 0100 : 2.000000 0100 : 2.000000 0100 : 2.000000 ffff : -0.007812

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by