diff options
author | priyanka | 2015-06-24 15:03:17 +0530 |
---|---|---|
committer | priyanka | 2015-06-24 15:03:17 +0530 |
commit | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch) | |
tree | ab291cffc65280e58ac82470ba63fbcca7805165 /273/CH25/EX25.16 | |
download | Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2 Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip |
initial commit / add all books
Diffstat (limited to '273/CH25/EX25.16')
-rwxr-xr-x | 273/CH25/EX25.16/ex25_16.sce | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/273/CH25/EX25.16/ex25_16.sce b/273/CH25/EX25.16/ex25_16.sce new file mode 100755 index 000000000..ed4512380 --- /dev/null +++ b/273/CH25/EX25.16/ex25_16.sce @@ -0,0 +1,43 @@ +clc;//clears the command window
+clear;//clears all the variables
+//example 25.16
+//decimal to binary conversion
+
+format('v',18);//changing the default prcision to 20 significant digits
+
+i=1;x=1;//flag bits
+
+dec=43.3125;//given decimal number which should be expressed in binary
+temp2=floor(dec);//separating integer part from the given number
+temp4=modulo(dec,1);//separating decimal part from the given number
+
+while(temp2>0)//storing each integer digit in vector for convenience
+ p(i)=(modulo(floor(temp2),2))
+ temp2=floor(temp2/2);
+ i=i+1;
+end
+
+temp2=0;//clearing temporary variable 'temp2'
+
+for j=1:length(p)
+//multipliying bits of integer part with their position values and adding
+ temp2=temp2+(p(j)*10^(j-1));
+end
+
+while(temp4~=0) //storing each decimal digit in vector for convenience
+ temp4=temp4*2;
+ d(x)=floor(temp4);
+ x=x+1;
+ temp4=modulo(temp4,1);
+end
+
+temp5=0;//clearing temporary variable 'temp5'
+
+for j=1:length(d)
+//multipliying bits of decimal part with their position values and adding
+ temp5=temp5+(10^(-1*j)*d(j))
+end
+
+temp3=temp2+temp5;
+//finally adding both the integer and decimal parts to get total output.
+disp(temp3,'the equivalent binary number is');
\ No newline at end of file |