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

4 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 29 Okt. 2020
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.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by