Hello everyone;
I need to write a easy programme which take inputs of a decimal integer or decimal fractions (positive or negative) of a matrix and a bit value that want to be converted from decimal to binary than back decimal value.
I have written a programme for just one value:
clear all
clc
a=input('Enter a decimal integer or a decimal with fractions: ');
n=input('Enter a bit value that want to be converted from decimal to binary than back decimal value: ');
for k=1:n;
a=a*2;
if (a<=1) y(k)=0
else
y(k)=1
a=a-1;
end
end
sum=0
for k=1:n;
sum=sum+y(k)*2^(-k)
end
This programme works for just a value but I couldn't bring the matrice values one by one then combine it.
For easy understand I want to explain with an example: Let f= [0.128 -1.35 0.489 3.547]
I need an fnew= [0.1275 -1.347 ... ] (not same just example)
I am trying to get error between the original and converted. I need your help please Thanks from now