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
0 个评论
回答(1 个)
Walter Roberson
2018-3-29
1 个评论
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 Center 和 File Exchange 中查找有关 Particle & Nuclear Physics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!