How to convert floating point to binary bits with the given condition?

3 ビュー (過去 30 日間)
N M Channabasavayya
N M Channabasavayya 2020 年 10 月 29 日
コメント済み: N M Channabasavayya 2020 年 10 月 29 日
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

採用された回答

Walter Roberson
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 ExchangeNumeric Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by