convert decimal values to binary?
1 view (last 30 days)
sa(i) = mod (ya(i)* (10^12) , 256);
sabinary(i) = dec2bin(round(sa(i) * (2^10)), 8) - '0';
This is the code to find 'sa'. I got values for sa(i) but i cant convert those values of 1D array to binary. Please help me with the above code.
Walter Roberson on 19 Jul 2017
The following is for R2016b or later, specifically to use a facility that allows the entire binary value to be stored into a single location, since that is how you seem to expect the output to be.
N = 41616;
sabinary = strings(1, N);
sabinary(1) = string('00000000');
for K = 2:N
sa(K) = mod (ya(K)* (10^12) , 256);
sabinary(K) = string(dec2bin(round(sa(K) * (2^10)), 8));
sa_recovered = bin2dec(sabinary) / 2^10;