Signed binary fraction into signed twos complement with one or two guard bits in the sign.

3 次查看(过去 30 天)
Does anyone know a function to convert a given set of numbers (signed fractional eg.: -1.8798734803, 1.0000000 -1.000000 etc..) into something like: sign bit|integer bit|integer bit|.|fractional bit|.....|fractional bit|
any help is valued. Regards

回答(1 个)

Walter Roberson
Walter Roberson 2018-3-29
  1 个评论
Walter Roberson
Walter Roberson 2018-3-30
signbit = X < 0;
if any(abs(X) >= 2^number_of_integer_bits)
error('Values are too large for that many integer bits');
end
other_bits = dec2bin(abs(X) * 2^number_of_fraction_bits,number_of_integer_bits+number_of_fraction_bits)-'0';
bits = [signbit(:), other_bits];

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Particle & Nuclear Physics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by