How to convert floating point to binary bits with the given condition?
3 次查看(过去 30 天)
显示 更早的评论
I have generated random numbers using rand() function.
a=rand(4,4);
out1=[0.868694705363510,0.800068480224308,0.263802916521990,0.579704587365570;
0.0844358455109103,0.431413827463545,0.145538980384717,0.549860201836332;
0.399782649098897,0.910647594429523,0.136068558708664,0.144954798223727;
0.259870402850654,0.181847028302853,0.869292207640089,0.853031117721894]
Now I want to convert thsese random numbers to binary with a condition.
Condition- If the 4th digit after the decimal point is >5, then that number should be converted to '1' else converted to '0'.
Example- let 0.868694705363510, here the 4th digit after te decimal point is 6 which is >5,
so, 0.868694705363510 should be converted to '1'.
Similarly, 0.800068480224308 , 4th digit is 0, so should be converted to '0'.
Like the above mentioned example, I want convert the out1 matrix to binary.
Help me out
Thank you
0 个评论
采纳的回答
Walter Roberson
2020-10-29
mod(a*10^4,10)>=6
Here I am taking you literally on the > 5 as not including 5 -- so it should only convert for 6, 7, 8, or 9 in that digit.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!